正在创建在新标签页中打开链接的 chrome 扩展并尝试点击新打开的标签页上的按钮 -
我可以使用扩展程序打开新选项卡,但内容脚本未在新选项卡上执行。
<块引用>清单文件
{
"manifest_version": 2,
"name": " New Tab Launcher",
"description": "Create the tab and button click ",
"version": "1.0",
"icons": {
"16": "icon.png",
"48": "icon.png",
"128": "icon.png"
},
"browser_action": {
"default_popup": "popup.html"
},
"permissions": [
"activeTab",
"tabs"
],
"content_scripts": [
{
"matches": [
"http://*/*", "https://*/*"
],
"js": [
"jquery-3.6.0.slim.min.js","contentScript.js"
],
"run_at": "document_end"
}
]
}
<块引用>
popup.js
document.addEventListener('DOMContentLoaded', function() {
var checkPageButton = document.getElementById('addMeetingUrl');
checkPageButton.addEventListener('click', function() {
chrome.tabs.create({'url': "youtube.com"});
}, false);
}, false);
<块引用>
contentScript.js
alert("This is test");
$(document).load(function (e) {
alert("Testing content script" +$('#logo').text());
});
在上面第一个警报成功通过下一个脚本未启动。
我试过删除 $(document).load
和添加 $(document).ready
都对我不起作用。
答案 0 :(得分:0)
#logo 可以在 load 和 ready 事件触发后添加到 DOM。 如果我说的是真的,请与调试器核对。 如果是这样,您将需要使用 MutationObserver。
答案 1 :(得分:0)
尝试删除“run at”,因为它会默认为“document_idle”,这通常是更安全的选项