Merge pull request #219 from simple-login/fix/extension-automatic-setup

fix: extension automatic setup
This commit is contained in:
Adrià Casajús
2024-07-15 10:20:27 +02:00
committed by GitHub
5 changed files with 21 additions and 46 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "simplelogin-extension", "name": "simplelogin-extension",
"version": "2.11.1", "version": "3.0.5",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "simplelogin-extension", "name": "simplelogin-extension",
"version": "2.11.1", "version": "3.0.5",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.36", "@fortawesome/fontawesome-svg-core": "^1.2.36",
-33
View File
@@ -1,33 +0,0 @@
import browser from "webextension-polyfill";
import SLStorage from "../popup/SLStorage";
async function setupContentScript() {
const apiUrl = SLStorage.get(SLStorage.SETTINGS.API_URL);
browser.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (
tab.url.startsWith("chrome") || // chrome internal pages
tab.url.startsWith("about") || // firefox internal pages
tab.url.startsWith("moz") || // firefox internal pages
tab.url.startsWith(apiUrl) // app domain
) {
return;
}
browser.scripting
.registerContentScripts([
{
id: "input-tools",
js: ["content_script/input_tools.js"],
css: ["content_script/input_tools.css"],
persistAcrossSessions: false,
matches: ["*://*/*"],
runAt: "document_idle",
},
])
.then(() => console.log("registration input tools complete"))
.catch((err) => console.warn("unexpected error", err));
});
}
setupContentScript();
+6 -7
View File
@@ -2,7 +2,6 @@ import browser from "webextension-polyfill";
import APIService, { API_ROUTE } from "../popup/APIService"; import APIService, { API_ROUTE } from "../popup/APIService";
import SLStorage from "../popup/SLStorage"; import SLStorage from "../popup/SLStorage";
import Onboarding from "./onboarding"; import Onboarding from "./onboarding";
import "./content-script";
import { handleNewRandomAlias } from "./create-alias"; import { handleNewRandomAlias } from "./create-alias";
import { import {
@@ -66,13 +65,12 @@ async function handleExtensionSetup() {
/** /**
* Check if a message comes from an authorized source * Check if a message comes from an authorized source
* @param {string} url * @param {string} url
* @returns boolean * @returns Promise<boolean>
*/ */
const isMessageAllowed = (url) => { const isMessageAllowed = async (url) => {
const requestUrl = new URL(url); const requestUrl = new URL(url);
const apiUrl = new URL( const apiUrlValue = await SLStorage.get(SLStorage.SETTINGS.API_URL);
SLStorage.DEFAULT_SETTINGS[SLStorage.SETTINGS.API_URL] const apiUrl = new URL(apiUrlValue);
);
let allowedSources = [ let allowedSources = [
new RegExp(apiUrl.hostname), new RegExp(apiUrl.hostname),
@@ -119,7 +117,8 @@ browser.runtime.onMessage.addListener(async function (request, sender) {
} }
// Check messages allowed only from authorized sources // Check messages allowed only from authorized sources
if (!isMessageAllowed(sender.url)) return; const messageAllowed = await isMessageAllowed(sender.url);
if (!messageAllowed) return;
if (request.tag === "EXTENSION_SETUP") { if (request.tag === "EXTENSION_SETUP") {
return await handleExtensionSetup(); return await handleExtensionSetup();
+11 -2
View File
@@ -53,5 +53,14 @@
}, },
"description": "Open the extension action menu" "description": "Open the extension action menu"
} }
} },
} "content_scripts": [
{
"js": ["content_script/input_tools.js"],
"css": ["content_script/input_tools.css"],
"matches": ["http://*/*", "https://*/*"],
"exclude_matches" : ["https://app.simplelogin.io/dashboard/*"],
"run_at": "document_idle"
}
]
}
+2 -2
View File
@@ -119,12 +119,12 @@ const config = {
if (process.env.FIREFOX) { if (process.env.FIREFOX) {
jsonContent.background = { jsonContent.background = {
"scripts": ["background.js"] "scripts": ["background.js"]
} };
} else { // CHROME } else { // CHROME
jsonContent.background = { jsonContent.background = {
"service_worker": "background.js", "service_worker": "background.js",
"type": "module" "type": "module"
} };
} }
if (process.env.LITE) { if (process.env.LITE) {