我有一个chrome扩展,我想在GitHub上操作一些DOM。当我刷新任何给定的页面时,它们都可以正常工作,但是如果我通常导航到该页面,脚本就不会被执行。
manifest.json
{
"manifest_version": 2,
"name": "Name",
"description": "Detailed description",
"version": "1.3.5",
"content_scripts": [{
"matches": ["https://github.com/*/*/issues/*"],
"js": ["jquery-2.1.0.min.js", "index.js"]
}],
"browser_action": {
"default_icon": "icon.png"
},
"permissions": [
"activeTab",
"https://ajax.googleapis.com/"
]
}index.js
$(document).ready(function() {
// DOM manipulating code
// removed for brevity
});发布于 2016-09-21 23:31:18
当您从另一个页面导航到GitHub页面时,页面中的容器将被更新,而不是整个页面。
所以根据我的经验..。如果您从回购的主页开始并切换到问题页面,扩展并不总是注意到此更改。因此,我建议将清单matches更改为所有github,而不仅仅是问题:
{
"manifest_version": 2,
"name": "Name",
"description": "Detailed description",
"version": "1.3.5",
"content_scripts": [{
"matches": ["https://github.com/*"],
"js": ["jquery-2.1.0.min.js", "index.js"]
}],
"browser_action": {
"default_icon": "icon.png"
},
"permissions": [
"activeTab",
"https://ajax.googleapis.com/"
]
}如果这不起作用,那么在您的代码中,监视"pjax:end“事件的文档:
document.addEventListener("pjax:end", function() {
// run code/call function
});https://stackoverflow.com/questions/39627817
复制相似问题