diff --git a/package.json b/package.json index 1938df0..1e79022 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "no-otp", - "version": "3", + "version": "3.1", "description": "Add to the input your OTP", "main": "index.js", "scripts": { diff --git a/public/index.html b/public/index.html deleted file mode 100644 index e9d269d..0000000 --- a/public/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - NO+OTP - - - -
- - - diff --git a/public/manifest.json b/public/manifest.json index 286df08..04b3097 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -1,8 +1,9 @@ { - "manifest_version": 2, + "manifest_version": 3, "name": "NO+OTP", "description": "Add to the input your password + OTP", - "version": "3.0", + "version": "3.1", + "action": {}, "options_ui": { "page": "options.html", "browser_style": false, @@ -22,7 +23,8 @@ "default_title": "NO+OTP" }, "background": { - "page": "index.html" + "service_worker": "js/index.js", + "type": "module" }, - "permissions": ["storage", "activeTab", "clipboardWrite"] + "permissions": ["storage", "activeTab", "clipboardWrite", "offscreen", "scripting"] } diff --git a/public/offscreen.html b/public/offscreen.html new file mode 100644 index 0000000..c1aaa31 --- /dev/null +++ b/public/offscreen.html @@ -0,0 +1,3 @@ + + + diff --git a/public/offscreen.js b/public/offscreen.js new file mode 100644 index 0000000..6985876 --- /dev/null +++ b/public/offscreen.js @@ -0,0 +1,74 @@ +// 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. + +// Once the message has been posted from the service worker, checks are made to +// confirm the message type and target before proceeding. This is so that the +// module can easily be adapted into existing workflows where secondary uses for +// the document (or alternate offscreen documents) might be implemented. + +// Registering this listener when the script is first executed ensures that the +// offscreen document will be able to receive messages when the promise returned +// by `offscreen.createDocument()` resolves. +chrome.runtime.onMessage.addListener(handleMessages); + +// This function performs basic filtering and error checking on messages before +// dispatching the +// message to a more specific message handler. +async function handleMessages(message) { + // Return early if this message isn't meant for the offscreen document. + if (message.target !== 'offscreen-doc') { + return; + } + + // Dispatch the message to an appropriate handler. + switch (message.type) { + case 'copy-data-to-clipboard': + handleClipboardWrite(message.data); + break; + default: + console.warn(`Unexpected message type received: '${message.type}'.`); + } +} + +// We use a