Skip to content

Commit

Permalink
Windows api mv3 sample (GoogleChrome#959)
Browse files Browse the repository at this point in the history
* WIP windows API sample

* Update background.js

* Added mv3 windows API sample

* Corrections based on review
  • Loading branch information
IanStanion-google authored Jun 21, 2023
1 parent cd11c73 commit 2527b66
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
14 changes: 14 additions & 0 deletions api-samples/windows/README.md
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.
Binary file added api-samples/windows/arrow_in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions api-samples/windows/background.js
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);
17 changes: 17 additions & 0 deletions api-samples/windows/manifest.json
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
}
Binary file added api-samples/windows/merge_windows_128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added api-samples/windows/merge_windows_48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2527b66

Please sign in to comment.