#1254 checkTabCS Changes

This commit is contained in:
Grzegorz Zając 2023-09-14 10:59:25 +02:00
parent 3ce4d7d458
commit 7171f5a900
4 changed files with 24 additions and 5 deletions

View File

@ -22,14 +22,20 @@ const setIcon = require('./setIcon');
const dummyGetLocalStorage = require('./dummyGetLocalStorage');
const checkTabCS = async tabId => {
await new Promise(resolve => setTimeout(resolve, 50));
await new Promise(resolve => setTimeout(resolve, 100));
await dummyGetLocalStorage();
let tabInfo;
if (!tabId) {
return;
}
const tabInfo = await browser.tabs.get(tabId);
try {
tabInfo = await browser.tabs.get(tabId);
} catch (e) {
return;
}
const tabUrl = tabInfo.url ? tabInfo.url : tabInfo.pendingUrl;
const extUrl = browser.runtime.getURL('');
let urlObj;
@ -42,6 +48,7 @@ const checkTabCS = async tabId => {
try {
urlObj = new URL(tabUrl);
} catch (e) {
await setIcon(tabId, false, false);
return;
}

View File

@ -27,7 +27,7 @@ const onTabUpdated = async (tabID, changeInfo) => {
return false;
}
if (tabID && changeInfo.status === 'complete') {
if (tabID && (changeInfo.status === 'complete' || changeInfo.favIconUrl || changeInfo.isArticle)) {
await checkTabCS(tabID);
}

View File

@ -20,7 +20,7 @@
import './styles/content_script.scss';
const browser = require('webextension-polyfill');
const { observe, createObserver } = require('./observer');
const { getTabData, getInputs, addInputListener, portSetup } = require('./functions');
const { getTabData, getInputs, addInputListener, portSetup, isInFrame } = require('./functions');
const contentOnMessage = require('./events/contentOnMessage');
const { loadFromLocalStorage, saveToLocalStorage } = require('../localStorage');
const storeLog = require('../partials/storeLog');
@ -63,7 +63,15 @@ const contentScriptRun = async () => {
const mutationObserver = createObserver();
observe(mutationObserver);
const onMessageListener = request => contentOnMessage(request, tabData);
const onMessageListener = request => {
if (request?.action === 'contentScript') {
if (isInFrame()) {
return false;
}
}
return contentOnMessage(request, tabData);
};
browser.runtime.onMessage.addListener(onMessageListener);
window.addEventListener('beforeunload', async () => {

View File

@ -71,6 +71,10 @@ const contentOnMessage = async (request, tabData) => {
break;
}
case 'contentScript': {
return { status: 'ok' };
}
default: {
return { status: 'error' };
}