我的扩展程序的contentscript
正在包含多个iframe的页面中多次加载。有办法防止这种情况吗?
我已经尝试过做有关该帖子的建议:chrome extension script is loading twice even more on some pages,但它仍然加载多次。
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (tab.status === 'complete' && changeInfo.status === "complete") {
chrome.browserAction.getBadgeText({}, function(result) {
if (result === "ON") {
setTimeout(function() {
chrome.tabs.executeScript(tab.id, { file: "js/contentscript.js", allFrames: true, runAt: "document_idle" }, result => {
// Ignores the permission issue when trying to inject the
// content script to local file of chrome extension.
const lastErr = chrome.runtime.lastError;
if (lastErr) return;
});
}, 100);
}
});
} else {
chrome.tabs.executeScript(tab.id, { code: "(c = document.querySelectorAll('#button')) ? c.forEach(panel => { panel.parentNode.removeChild(panel); }) : null;" },
result => {
// Ignores the permission issue when trying to inject the
// content script to local file of chrome extension.
const lastErr = chrome.runtime.lastError;
if (lastErr) return;
});
}
});