Page 1 of 1

Script authors: W.map API changed

Posted: Wed Nov 20, 2019 2:11 pm
by Glodenox
As you may have noticed, many scripts are currently broken. The reason for this is the removal of various methods that used to be available in the W.map object. This object gives access to the OpenLayers instance used to draw the Waze map. As you may expect, this is one of the key sections of the WME used by a lot of scripts.

Several of the most common methods remain available, but several others are now hidden away. It is however still possible to access these methods by using W.map.getOLMap().

As a temporary workaround to make "outdated" and old scripts work again, I've created a little userscript that copies over all methods from the W.map.getOLMap object, unless they still exist: https://greasyfork.org/scripts/391783-w ... map-object This will probably work best if the script is executed before the other userscripts.

Re: Script authors: W.map API changed

Posted: Tue Dec 03, 2019 8:36 am
by Glodenox
Sure! I can easily adjust the code for that.

Re: Script authors: W.map API changed

Posted: Wed Dec 04, 2019 11:58 am
by Glodenox
I've updated the Fix Map Object script, but I've gone for a slightly different approach after realising that the script would be missing out on reporting the use of any non-function properties.

I've pretty much replaced W.map with a Proxy object and keep track of which properties the script has recovered. This way I know for each property access whether or not I need to trigger a message in the console. To prevent spamming the console too much, I've also made it so that the use of a certain property will only be reported 10 times at most.

I first tried to add the removed properties as a Proxy object, but that doesn't work for primitive values as they'd suddenly get a Proxy object instead of a number or String.

In theory it could be that a value property that has been copied over was null, but got replaced after the recovery. The script will check every two seconds whether or not all properties that were null are still the same. It will not keep primitive values in sync between the two objects though. I don't think that is needed here, even though it is possible by also wrapping the OL Map object in a Proxy that listens to "set" actions. That just seems like too much effort for what it's worth.

Re: Script authors: W.map API changed

Posted: Wed Dec 04, 2019 10:17 pm
by Glodenox
Eh, I'm also just bashing rocks together until they form a nice bridge. Sometimes I accidentally end up with a nice house instead and decide to keep it :lol: I've learnt stuff as well by doing this as I hadn't successfully used the Proxy class in the past, for example. And somewhere halfway solving this, the code was about 3 times as long and was choking up my browser with console log loops.

Re: Script authors: W.map API changed

Posted: Tue Dec 03, 2019 12:26 am
by iainhouse
Hi Glodenox

After several days, during which I've learned quite a bit about Javascript, I've modified the code for WME Fix Map Object so that it will log to the console every attempt to use a function that you've copied from W.map.olMap to W.map. Here's an example:
WME_FMO.png
(8.26 KiB) Downloaded 834 times
Would you be interested in adding this modification to WME Fix Map Object? It should help with identifying scripts which are only working because they are relying on it.

Re: Script authors: W.map API changed

Posted: Tue Dec 03, 2019 9:08 pm
by iainhouse
Sorry for the delay - I currently have no Waze access at work. :)

Code: Select all

    function init() {
        if (typeof W === 'undefined' ||
            typeof W.map === 'undefined' ||
            typeof W.map.olMap === 'undefined') {
            setTimeout(init, 100);
            return;
        }
        function intercept(propName, destFunction) {
            return function() {
                console.groupCollapsed ("WME FMO: Removed function W.map." + propName + " called. Expand for stack trace.");
                console.log ((new Error()));
                console.groupEnd();
                return destFunction.apply(W.map.olMap,arguments);
           }
        }
        // Go through all properties, including the prototype chain
        console.groupCollapsed("WME FMO: copying W.map.olMap functions to W.map...");
        for (var mapProperty in W.map.olMap) {
            if (!W.map[mapProperty]) {
                  console.log("WME FMO processing " + mapProperty);
                  W.map[mapProperty] = intercept(mapProperty, W.map.olMap[mapProperty]);
            }
        }
        console.groupEnd();
    }
There's some logging in there when the properties get copied - you don't necessarily need to include that. I had real fun learning about Javascript closures and why you shouldn't create functions inside a loop. Finding a way to refer back to whoever called the function was also a struggle. :mrgreen:

I'm somewhat surprised at how few scripts are triggering the alerts. Validator did yesterday and I must report it if I find it again. I think it's possible Waze may have put in some crosslinks themselves: the current definition of W.map.getZoom is ƒ (){return this.olMap.getZoom()}, and that's without any scripts running.

Also, very amusingly, I've just spotted an attempt to use W.map.raiseLayer - by WME itself! If I weren't running WME Fix Map Object, that would have failed. :lol:

Re: Script authors: W.map API changed

Posted: Wed Dec 04, 2019 8:49 pm
by iainhouse
Thanks Tom. :mrgreen:

That looks considerably more complex than what I had - I should have known it was a job better handed to someone who really knows what they're doing! :lol: I would have just asked you to add the functionality, but I thought I'd try doing it myself and certainly had some fun trying.

Re: Script authors: W.map API changed

Posted: Wed Nov 20, 2019 2:36 pm
by tunisiano18
For those that want to know, WME Sent-to-slack has been corrected.