gpt4 book ai didi

javascript - 防止内容脚本因页面 iframe 而多次加载

转载 作者:行者123 更新时间:2023-12-05 03:58:26 25 4
gpt4 key购买 nike

我的扩展程序的 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;
});
}
});

最佳答案

enter image description here

删除那个,默认为false

关于javascript - 防止内容脚本因页面 iframe 而多次加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58021352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com