Google chrome chrome扩展能否更改页面字符集?
我是chrome扩展开发的新手。我想使用扩展来更改页面字符集,比如chrome设置>>工具>>字符集。我看到了关于chrome.contentSetting的chrome扩展文档。但是我没有找到如何更改页面字符集。是的。通过: 这两个函数中的任何一个都位于加载到Google chrome chrome扩展能否更改页面字符集?,google-chrome,google-chrome-extension,Google Chrome,Google Chrome Extension,我是chrome扩展开发的新手。我想使用扩展来更改页面字符集,比如chrome设置>>工具>>字符集。我看到了关于chrome.contentSetting的chrome扩展文档。但是我没有找到如何更改页面字符集。是的。通过: 这两个函数中的任何一个都位于加载到manifest.json中的background.js文件中: { "manifest_version": 2, // name,description,version... "background": {
manifest.json
中的background.js
文件中:
{
"manifest_version": 2,
// name,description,version...
"background": {
"scripts": ["background.js"],
"persistent": true,
//"matches": ["https://google.com/"]
},
"permissions": [
"tabs",
"webRequest",
"webRequestBlocking"
]
}
一旦页面初始化并呈现,就无法更改字符集<代码>文档。字符集为只读,触发重新呈现似乎不会影响文档字符集,即使已更改。这是一种在加载页面之前更改它的解决方案;对于已经加载的页面,问题仍然存在。所以我想加载后更改的最佳近似值是“激活webRequest侦听器,重新加载,停用侦听器”。这会起作用-实际上是一个独立扩展的好主意。是的,除了不能假设重新加载URL没有副作用之外。用户必须知道。您的扩展是否已发布?
chrome.webRequest.onCompleted.addListener(function(details){
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.executeScript(null, {allFrames:true,code:"document.getElementsByTagName('meta')[0].setAttribute('content', 'text/html; charset=UTF-8');"});
});
}, {urls: ['http://google.com/']});
{
"manifest_version": 2,
// name,description,version...
"background": {
"scripts": ["background.js"],
"persistent": true,
//"matches": ["https://google.com/"]
},
"permissions": [
"tabs",
"webRequest",
"webRequestBlocking"
]
}