问题描述:

Is it possible to turn JavaScript on/off with a self-made Google Chrome extension?

For example, in Opera browser, there are simple possibilities to do that with widgets, user-made buttons, etc., but I didn't find any solutions to do that in Chrome (my first source was the official Google Chrome extensions' documentations).

A strange aspect is that I need JavaScript to run the extension itself...if I'm able to turn JavaScript off with an extension, can I still use JavaScript in my extension after doing it?


Edit:

It's already possible to do it via chrome.contentSettings.javascript!

See this example which shows how to use it (Quick JavaScript Switcher extension, which mlb linked here).

网友答案:

It's now possible with the ContentSettings API,
and there is an extension named Quick Javascript Switcher that turns on/off javascript on the fly : https://github.com/maximelebreton/quick-javascript-switcher

QJS on the Chrome Webstore : https://chrome.google.com/webstore/detail/geddoclleiomckbhadiaipdggiiccfje

Enjoy !

seo : disable javascript chrome extension

网友答案:

It seems currently it is not possible for extensions to disable JavaScript support. There is even a feature request for that in the Chromium tracking site. We need to be patient and wait until Google decides to support that.

网友答案:

Currently, we can NOT access chrome://settings/content data with your Chrome extension

In my code, when tab "chrome://settings/content" created, the alert(0) does NOT work, and always get the follow error:

Error during tabs.executeScript: Cannot access contents of url "chrome://settings/content". Extension manifest must request permission to access this host.

but when tab "http://www.google.com.hk" created, alert(0) works.

So I think we can NOT access chrome://settings/* data :

popup.html:

<html>
<head>
<script>
  function openSetting() {
    chrome.tabs.create({"url":"chrome://settings/content", "selected":true});
  }

  function openGoogle() {
    chrome.tabs.create({"url":"http://www.google.com.hk", "selected":true});
  }

  //chrome.browserAction.onClicked.addListener(enableDisableImage);

    chrome.tabs.onCreated.addListener(function(tab) {
        chrome.tabs.executeScript(null, {code:"alert(0)"});
    });
</script>
</head>
<body>
<input type="button" onClick="openSetting()" value="Switch"/>
<input type="button" onClick="openGoogle()" value="Switch"/>
</body>
</html>

manifest.json:

{
  "name": "ImageSwitcher",
  "version": "1.0",
  "description": "Disable/Enable loading image",
  "browser_action": {
    "default_icon": "icon.png",
        "default_popup": "popup.html"
  },
  "permissions": [
    "tabs",
        "*://*/*"
  ]
}
网友答案:

It's now possible with the release version of chrome (as of chrome 16) to toggle java-script off and on from an extension.

Here's an extension which does just that:

https://chrome.google.com/webstore/detail/geddoclleiomckbhadiaipdggiiccfje

相关阅读:
Top