Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome chrome扩展能否更改页面字符集?_Google Chrome_Google Chrome Extension - Fatal编程技术网

Google chrome 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": {

我是chrome扩展开发的新手。我想使用扩展来更改页面字符集,比如chrome设置>>工具>>字符集。我看到了关于chrome.contentSetting的chrome扩展文档。但是我没有找到如何更改页面字符集。

是的。通过:

这两个函数中的任何一个都位于加载到
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"
    ]
}