1

I installed Google chrome extension cjs (Custom JavaScript for Website).

The script is working fine if I am writting the script inside the cjs editor:

enter image description here

I wrote the script in a js file and put it in my IIS as following:

  • Open IIS Manager
  • Right-click Default Web Site
  • Add Application
  • Alias = googleScript
  • Physical path: C:\scripts\google (for example)
  • I created a googleScript.js file and saved it in C:\scripts\google. The content of the file is: alert("Google");
  • I clicked on Connect As and select Application user (pass-through authentication)
  • I opened the Default Document located in the googleScript (in IIS) and Add a new Default Document named: googleScript.js
  • When I right-click on googleScript and select Manage Application->Browse, a new web page is being opened with the script I wrote. THe url of the page is http://localhost/googleScript/
  • Now back to cjs extension, instead of alert("Google"); I wrote //localhost/googleScript/googleScript.js;.

enter image description here

When calling the script file, the alert is not working anymore. WHat is the correct way to call a script file from cjs chrome extension?

ehh
  • 3,412
  • 7
  • 43
  • 91

2 Answers2

0

Read

before proceeding...


I created a small weave you can use to experiment with this idea for your application/extension.

Now this is one way to grab and save an external scripts source online.

var download_to_textbox = function (url, el) {
      return $.get(url, null, function (data) {
        el.val(data)
      }, "text")
    };

Grab script source code and add it to a textarea

download_to_textbox('libraries/alertifyjs/css/alertify.min.css', $('.alertifyjs1'));

Save file using FileSaver.js - https://github.com/eligrey/FileSaver.js/

var blob = new Blob([ $('.alertifyjs1').val() ], {type: "text/html"});
saveAs(blob, "alertify.min.css");
Community
  • 1
  • 1
Michael Schwartz
  • 8,153
  • 14
  • 81
  • 144
0

Here's how I did it on Chrome 85 with Custom JavaScript for Websites 2, version 3.4.5. This isn't good to do permanently, the Chrome team had good reasons for disabling unsecured requests to localhost.

  1. Enable chrome://flags/#allow-insecure-localhost (paste that into the URL bar)

  2. Add http://localhost to chrome://flags/#unsafely-treat-insecure-origin-as-secure and enable it

  3. Restart Chrome

  4. In a terminal window, create a directory containing your javascript file (let's say it's called my-script-file.js)

  5. Serve that directory by cd'ing into it and running python3 -m http.server

  6. add this line to cjs:

//localhost:8000/my-script-file.js

(python3 -m http.server serves on port 8000 by default)

  1. click "Save" in the top left of the CJS popup

You should now see requests for //localhost:8000/my-script-file.js in the Network tab of the Chrome DevTools.

Boris Verkhovskiy
  • 14,854
  • 11
  • 100
  • 103