forked from GoogleChrome/chrome-extensions-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Windows api mv3 sample (GoogleChrome#959)
* WIP windows API sample * Update background.js * Added mv3 windows API sample * Corrections based on review
- Loading branch information
1 parent
cd11c73
commit 2527b66
Showing
6 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# chrome.windows | ||
|
||
This sample demonstrates using the `chrome.windows` and `chrome.tabs` API to manage tabs across different windows. | ||
|
||
## Overview | ||
|
||
The extension interates across all tabs and moves them to the currently active window. | ||
|
||
## Running this extension | ||
|
||
1. Clone this repository. | ||
2. Load this directory in Chrome as an [unpacked extension](https://developer.chrome.com/docs/extensions/mv3/getstarted/development-basics/#load-unpacked). | ||
3. Make sure you have multiple windows of chrome open. | ||
4. Pin the extension and click on the action button. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
async function start() { | ||
const current = await chrome.windows.getCurrent(); | ||
|
||
const allTabs = await chrome.tabs.query({}); | ||
allTabs.forEach((tab) => { | ||
if (tab.windowId != current.id) { | ||
chrome.tabs.move(tab.id, { | ||
windowId: current.id, | ||
index: tab.index | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
// Set up a click handler so that we can merge all the windows. | ||
chrome.action.onClicked.addListener(start); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "Merge Windows", | ||
"version": "1.0.3", | ||
"description": "Merges all of the browser's windows into the current window", | ||
"icons": { | ||
"48": "merge_windows_48.png", | ||
"128": "merge_windows_128.png" | ||
}, | ||
"background": { | ||
"service_worker": "background.js" | ||
}, | ||
"action": { | ||
"default_icon": "arrow_in.png", | ||
"default_title": "Merge Windows" | ||
}, | ||
"manifest_version": 3 | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.