3

I was up till 1 am last night trying to find an example of how to do this. My theory is that I'd write a function that would comment out all javascript.

The second option would be to add the url to the list of javascript settings.

Right now my extension is very simple:

function linkOnClick(info, tab) {
    window.open(info.linkUrl)
}

chrome.contextMenus.create(
{title: "Load with no Javascript", contexts:["link"], onclick: linkOnClick});

This is my first extension and I'm kind of lost.

edit: let me know if I should also post the manifest.json.

Isaac
  • 151
  • 5
  • Comment out all JavaScript where? On a page the user is visiting? Do you want to disable JavaScript? – xDaevax Sep 24 '14 at 14:43
  • Exactly. All I want it to do is disable javascript for the page it's opening. I'm trying to write an extension I really want, which I couldn't find in the chrome store. Everything seems to be working so far, except I'm clueless on how begin disabling the javascript on the link that's being loaded. – Isaac Sep 24 '14 at 14:47
  • Related: http://stackoverflow.com/questions/4663359/google-chrome-extension-how-to-turn-javascript-on-off, https://github.com/maximelebreton/quick-javascript-switcher, You should probably investigate the ContentSettings API: https://developer.chrome.com/extensions/contentSettings – xDaevax Sep 24 '14 at 14:49
  • It looks like I might be using ContentSetting.clear() to do it. I'll post later to say if that's what it actually is or not. – Isaac Sep 24 '14 at 15:01

1 Answers1

2

edit: I can't mark this as solved for 2 days (why? who knows.), so I'll probably not remember to mark this as solved. So accept this as the official making: SOLVED.

chrome.contentSettings.javascript.set is the thing that disables javascript.

Here's the part that disables javascript. (Google, here's what an actual example should look like):

    chrome.contentSettings.javascript.set(
        {'primaryPattern':AnyDomainName, /*this is a string with the domain*/
        'setting': "block", /* block the domain. Can be switched to "allow" */
        'scope':'regular'}, /*it's either regular or incognito*/
        function(){ 
            /*optional action you want to 
            take place AFTER something's been blocked'*/    
            });

Here's the script I used to import into my json script for my chrome extension.

var link=""
var pattern=""

function linkOnClick(info, tab) {
    r = /:\/\/(.[^/]+)/;
    link=info.linkUrl
    pattern="http://"+link.match(r)[1]+"/*"

    chrome.contentSettings.javascript.set(
        {'primaryPattern':pattern,
        'setting': "block",
        'scope':'regular'},
        function(){

        window.open(link)

        });
    }

chrome.contextMenus.create({title: "Load with no Javascript", contexts:["link"], onclick: linkOnClick});

I couldn't tell how any of this worked by reading the developer.chrome.com page! They really need add complete working examples or allow a way for users to add examples. I can't even use it. The git hub link is what saved me.

Isaac
  • 151
  • 5
  • Don't forget to _unset_ it. – Xan Sep 24 '14 at 19:51
  • You can't mark it as solved by your own answer, to give chance to others to contribute a better one. You should wait and do it - it will give you reputation points. – Xan Sep 24 '14 at 19:52
  • Other answers would be nice, but I don't think too many people are writing browser extensions, so I'd be surprised if someone else gave an answer. I'll add an unset. good idea – Isaac Sep 24 '14 at 23:39