From 2527b666a6b6d04be880feefb144512b79c20c80 Mon Sep 17 00:00:00 2001 From: IanStanion-google <112102430+IanStanion-google@users.noreply.github.com> Date: Wed, 21 Jun 2023 15:01:39 -0400 Subject: [PATCH] Windows api mv3 sample (#959) * WIP windows API sample * Update background.js * Added mv3 windows API sample * Corrections based on review --- api-samples/windows/README.md | 14 ++++++++++ api-samples/windows/arrow_in.png | Bin 0 -> 594 bytes api-samples/windows/background.js | 30 ++++++++++++++++++++++ api-samples/windows/manifest.json | 17 ++++++++++++ api-samples/windows/merge_windows_128.png | Bin 0 -> 5855 bytes api-samples/windows/merge_windows_48.png | Bin 0 -> 1970 bytes 6 files changed, 61 insertions(+) create mode 100644 api-samples/windows/README.md create mode 100644 api-samples/windows/arrow_in.png create mode 100644 api-samples/windows/background.js create mode 100644 api-samples/windows/manifest.json create mode 100644 api-samples/windows/merge_windows_128.png create mode 100644 api-samples/windows/merge_windows_48.png diff --git a/api-samples/windows/README.md b/api-samples/windows/README.md new file mode 100644 index 0000000000..a4a0d19c0d --- /dev/null +++ b/api-samples/windows/README.md @@ -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. diff --git a/api-samples/windows/arrow_in.png b/api-samples/windows/arrow_in.png new file mode 100644 index 0000000000000000000000000000000000000000..f0da7b150f6d1356f6eafb5f82e6343a2849d1a8 GIT binary patch literal 594 zcmV-Y0~VI0Nz7W;8j6kpH~30YW|cN8cU5gJ5C2ZzE*z%jG1$-ykjMBSig#+JxPnPjHP zUT*pn-0%rb`)tKU&jmAGc5yEL7r)<`Ie!fRO|%gpkxPGb{^Jx!?@sZ&wn?s6R+-)u zmeXHWvH3NHaDB2By6|zcAH4V*nmQGs!eyHjuZ9t;gdi5pM58oI>sJXJ{KzBoIf=+c z5Yz8HjKD_(C@>bPbJ%WVvG_Iu;iajm+UM$%(%PpL>|AYN?|Tk6-?L4GPqM) zM!Yf)+kvUYKR0sihMAgIg`a%eL9pUv1Wt*^)@26S`WhTX9u%hBZ`gzBGdFHjT?kYh z@V~J$0{hW8CJwLDX7B|g#-AF{7W`}eCxMp;pl_l}+mDs8ie_fSvHUQMyLuQN4PqoW z0R00U+5&gU%K1tn*3WMveV(FAGlJ2_daRtr5hu|$Oryd|b1No?u_Q;4I!n+uF@kGK zbBsg~IP}7?FJR!FR#FAd6HAlAcWX(^mIHr&%m{`b_QR0V!&7kLRw;~$JdeI?x1MZS-)x g+3uz`-9_mA6Syz5l{KF@h5!Hn07*qoM6N<$f`*g`;{X5v literal 0 HcmV?d00001 diff --git a/api-samples/windows/background.js b/api-samples/windows/background.js new file mode 100644 index 0000000000..c97232e5e1 --- /dev/null +++ b/api-samples/windows/background.js @@ -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); diff --git a/api-samples/windows/manifest.json b/api-samples/windows/manifest.json new file mode 100644 index 0000000000..6427c3befe --- /dev/null +++ b/api-samples/windows/manifest.json @@ -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 +} diff --git a/api-samples/windows/merge_windows_128.png b/api-samples/windows/merge_windows_128.png new file mode 100644 index 0000000000000000000000000000000000000000..a37b606559736a7451e54563249e19207bf9d0e8 GIT binary patch literal 5855 zcmV<579i<~P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2igJ* z05dlOvAGTa001I%MObu0Z*6U5Zgc=ca%Ew3Wn>_CX>@2HM@dakAa8CUVIWOmV~41B zLjV94F-b&0RCodGTI+5b$JzeAwtrjnU(uqygyQ{13`hWi#LXWRQv;I#!FkOc$ zl7n;Y6U5>I;_*1Lxg7F&$~ zo)L5szw_qx>mM4nwxH8*!f2p;jDeVgDq=t;nSgWGhia{XrYNG`XrNxN|CfzAYPA~5 znNAX*doI4`~65JlW==HDCZ8S7?==B)iO$rCQ8Ku@`WNQ*%WGZ z5&6R$+N~BUxhxvBDstsITFn+Zoen0G3C82`T%^ymJ8kUj?7(8Nn8=vFui!SY5Wu~A z_wH~UheRTQP&mZg`R3zI=K85H+-^7a_V!?RIEVl;5E4loW)Bc>xxsS*?AmPLf*}Mv zPK2XLWTF8i(5OE1Sk0ud9qtTd)q9`Jh$-w9HQLjP;@B;-sz(N3I zwcqLY`)q~I*z5I}?RLA2vvRxLX62b>{Jeg~HnpU_Ei22Oo13#|$r!1JQd$5D0hmmt zJ9s`oJ&{5JSfp6A-#;uZEnVN--1Gr}BuR|&@^Q`}E6VOkU&OiEKdqi391bfbfJKT$ z`y&Fw_VzaB6#yWi+LoZT?&JPe2}fhOIG$d%mn_Is)0hG?oTmU5DHe_NNdO3=(Kwd? zrc(*^F7W<+Gbl>s8tTn1q-GsMAqWa-T*Fb@1&T&jLZJpc+E*c(i(`xMgsuO zO8|=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