相关内容:
The Chrome extension popup is not working, click events are not handled
Javascript in Google Chrome popup extension not running
Cannot get Chrome popup.js to use console.log
manifest.json
{
"permissions": [
"activeTab",
"tabs",
"storage",
"<all_urls>",
"*://*.youtube.com/*",
],
"chrome_url_overrides": {
"newtab": "popup/popup.html"
},
"browser_action": {
"default_title": "My extension"
},
"background": {
"scripts": [
"background/background.js"
]
},
"content_scripts": [{
"js": [
"content/content.js"
],
"matches": [
"<all_urls>",
"*://*.youtube.com/*"
],
"run_at": "document_end",
"all_frames": true,
"match_about_blank": true
}],
"web_accessible_resources": [
"*.html",
"images/*"
],
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}popup.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Extension</title>
</head>
<body>
<div>dkafafdafldafkla This shows</div>
</body>
<script src="popup.js">
</script>
</html>popup.js
document.addEventListener("DOMContentLoaded", () => {
console.log("Adding dom load event listener; we don't get here :(");
chrome.tabs.create({
active: true,
url: "https://my.site.com/",
});
});该扩展似乎不可调试:

控制台中没有错误(包括网页和后台脚本);为什么单击弹出窗口时url没有打开(文本表单popup.html会出现在新选项卡中)。
发布于 2021-10-07 18:06:37
设法让它按预期运行;从上面的manifest.json中删除了chrome_url_overrides,并在background.js中添加了以下内容
chrome.tabs.onCreated.addListener(function(tab) {
console.log("Current tab: ", tab.url);
if (tab.url === "edge://newtab/") {
chrome.tabs.update(tab.id, {
url: "https://my.site.com/",
});
}
});发布于 2021-10-07 03:40:05
根据您的描述和您提供的清单代码,屏幕截图显示"Inspect popup“选项被禁用(灰显),所以我认为您的问题是manifest中没有"default_popup"声明。或者你可以使用chrome.browserAction.setPopup来解决这个问题。
这是一个类似的案例:Disable "inspect popup" menu entry in chrome extensions。
https://stackoverflow.com/questions/69472375
复制相似问题