marshmellooooooos marshmellooooooos - 8 days ago 6
Javascript Question

How to add user script js file as a Chrome extension?

I have been currently working on user scripts for Chrome that can function without the use of Tampermonkey. Today I added a third party extension (a userscript js) to the Chrome extensions:

// ==UserScript==
// @name "job changer"
// @namespace Marshmellows
// @version 0.1
// @description Change 'Jobs' in stackoverflow to Hello!
// @match http://stackoverflow.com/*
// @grant none
// @run-at document-start
// ==/UserScript==

document.addEventListener('DOMContentLoaded', function() {
document.getElementById('nav-jobs').innerHTML = 'Hello!';
}, false);


I added this to the Chrome extensions by simply dragging the file inside (it worked fine).

I restarted Chrome and discovered that it had completely blocked my js file extension. It does not let me click enable!
I can't seem to find a solution for this problem. I went on Chrome's forum and tried to find ways to create a
.crx
file. But because I am quite new to web development and the DOM, I feel like I need some guidance. Can anything be done?

Answer

As you discovered, although you can still install a plain userscript by dragging it to the chrome://extensions/ page, it will be automatically disabled when Chrome restarts. Google claims that this is to "protect" users from malicious extensions.

To keep your userscript from being auto disabled, you must pack it into an extension manually. See the steps at the "Controlling the Script and name" section of this answer.

Extensions installed this way will not be auto-disabled, but they will trigger a popup warning on every single start of Chrome!
Google refuses to provide developers any recourse to that popup. To avoid it, you must register your new extension in the Google Pay Store.

Unless you plan to graduate to extension development, or you just love needless hassle, it would be foolish to do this for a userscript. Just install Tampermonkey and enjoy how easy and powerful userscript development can be.