我有一个案例,我无法弄清楚发生了什么。我创建了一个覆盖空白新标签内容的 chrome 扩展。一切正常,但每当刷新时,我在其他已经打开的选项卡上遇到了一些错误。即使在现有窗口中也会执行扩展,给我带来麻烦。我一直在尝试使用
chrome_url_overrides: newtab
查找有关扩展生命周期的一些信息以了解其行为,但找不到任何信息。
[更新以包含完整示例,还有 here's 重现问题的最小示例 - 根据您的要求]
清单.json
{
"name": "Homepage",
"version": "1.0",
"manifest_version": 3,
"permissions": [
"identity"
],
"chrome_url_overrides": {
"newtab": "index.html"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["index.js"],
"type": "module"
}
]
}
script.js(都在里面)
console.log('Hello from Chrome Homepage');
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Homepage</title>
<script src="index.js"></script>
</head>
<body>
<home-page></home-page>
</body>
</html>
我可以想到几个选项来防止扩展在新选项卡打开之外执行,但首先会尝试理解为什么我的扩展也在当前选项卡中继续执行,而不是仅在打开空白选项卡时执行。
谢谢!