Overriding Javascript functions no longer works

90 views
Skip to first unread message

Andrew Daugherity

unread,
Nov 29, 2017, 8:16:04 PM11/29/17
to greasemonkey-users
One of my main uses of GreaseMonkey is a simple script to override a "Java detection" function embedded in an old device's firmware:
// ==UserScript==
// @name        Fix KVM Java detection
// @namespace   example.com
// @description Override Java plugin detection in APC (Avocent) IP KVMs
// @include     https://kvm1.example.com/*
// @include     https://kvm2.example.com/*
// @version     0.2
// @grant       none
// ==/UserScript==


// override the function defined in connectionslistiframe.js
function IsJavaInstalled() {
 
/* unconditionally return "yes":
       The KVM viewer just downloads a JNLP file which is opened with Java Web Start.
       Leave having a working 'javaws' up to the user.
  */

 
return 1;
}


addJS_Node
(IsJavaInstalled);


// http://stackoverflow.com/a/21274652
function addJS_Node (text, s_URL, funcToRun, runOnLoad) {
   
var D                                   = document;
   
var scriptNode                          = D.createElement ('script');
   
if (runOnLoad) {
        scriptNode
.addEventListener ("load", runOnLoad, false);
   
}
    scriptNode
.type                         = "text/javascript";
   
if (text)       scriptNode.textContent  = text;
   
if (s_URL)      scriptNode.src          = s_URL;
   
if (funcToRun)  scriptNode.textContent  = '(' + funcToRun.toString() + ')()';


   
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
    targ
.appendChild (scriptNode);
}



This script worked in GM 3.x (FF <= 56), and still works in ViolentMonkey (FF 57, Chrome) & TamperMonkey (Chrome, Edge). It simply doesn't run in GM 4.x, and no script-related errors are logged in the console.  (There is one error generated by the function I'm attempting to override, thus I'm pretty sure the script is not being run.)

I'm not calling any GM_* API stuff, but is there something else here that needs changing?  In an older version, I had used @grant unsafeWindow, which I know got renamed, but I discovered @grant none worked just as well, so I changed to that. (However, not having a @grant line at all did not work.)


Thanks,
Andrew
Reply all
Reply to author
Forward
0 new messages