Merge pull request #219 from simple-login/fix/extension-automatic-setup
fix: extension automatic setup
This commit is contained in:
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "simplelogin-extension",
|
||||
"version": "2.11.1",
|
||||
"version": "3.0.5",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "simplelogin-extension",
|
||||
"version": "2.11.1",
|
||||
"version": "3.0.5",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-svg-core": "^1.2.36",
|
||||
|
||||
@@ -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();
|
||||
@@ -2,7 +2,6 @@ import browser from "webextension-polyfill";
|
||||
import APIService, { API_ROUTE } from "../popup/APIService";
|
||||
import SLStorage from "../popup/SLStorage";
|
||||
import Onboarding from "./onboarding";
|
||||
import "./content-script";
|
||||
|
||||
import { handleNewRandomAlias } from "./create-alias";
|
||||
import {
|
||||
@@ -66,13 +65,12 @@ async function handleExtensionSetup() {
|
||||
/**
|
||||
* Check if a message comes from an authorized source
|
||||
* @param {string} url
|
||||
* @returns boolean
|
||||
* @returns Promise<boolean>
|
||||
*/
|
||||
const isMessageAllowed = (url) => {
|
||||
const isMessageAllowed = async (url) => {
|
||||
const requestUrl = new URL(url);
|
||||
const apiUrl = new URL(
|
||||
SLStorage.DEFAULT_SETTINGS[SLStorage.SETTINGS.API_URL]
|
||||
);
|
||||
const apiUrlValue = await SLStorage.get(SLStorage.SETTINGS.API_URL);
|
||||
const apiUrl = new URL(apiUrlValue);
|
||||
|
||||
let allowedSources = [
|
||||
new RegExp(apiUrl.hostname),
|
||||
@@ -119,7 +117,8 @@ browser.runtime.onMessage.addListener(async function (request, sender) {
|
||||
}
|
||||
|
||||
// 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") {
|
||||
return await handleExtensionSetup();
|
||||
|
||||
+11
-2
@@ -53,5 +53,14 @@
|
||||
},
|
||||
"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
@@ -119,12 +119,12 @@ const config = {
|
||||
if (process.env.FIREFOX) {
|
||||
jsonContent.background = {
|
||||
"scripts": ["background.js"]
|
||||
}
|
||||
};
|
||||
} else { // CHROME
|
||||
jsonContent.background = {
|
||||
"service_worker": "background.js",
|
||||
"type": "module"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (process.env.LITE) {
|
||||
|
||||
Reference in New Issue
Block a user