Windows api mv3 sample (#959)

* WIP windows API sample

* Update background.js

* Added mv3 windows API sample

* Corrections based on review
This commit is contained in:
IanStanion-google
2023-06-21 15:01:39 -04:00
committed by GitHub
parent cd11c730ea
commit 2527b666a6
6 changed files with 61 additions and 0 deletions

View File

@@ -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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 594 B

View File

@@ -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);

View File

@@ -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
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB