Fix for 2mdn.net

Proposals for new surrogate scripts, updates/bug fixes to existing ones, tips and tricks to work around the lazy web.
Post Reply
saaib
Posts: 3
Joined: Sat May 23, 2015 6:59 pm

Fix for 2mdn.net

Post by saaib » Tue Jun 02, 2015 10:08 pm

Hi again

a few weeks ago videos on a local news website in Belgium stopped working without 2mdn.net allowed. See this example: http://goo.gl/g77eho. It complained about google.ima.settings being undefined. So I added a __noSuchMethod__ function to catch calls to google.ima.settings. I am not exactly sure if this is the best way to extend the script surrogate but I can confirm it works like this.

The updated script surrogate for 2mdn.net I use is:

Code: Select all

if('Proxy' in window){let _f=function(){};google={};Object.defineProperty(google,'__noSuchMethod__',{configurable:true,enumerable:false,value:_f});let ima={};ima.AdsManagerLoadedEvent=ima.AdErrorEvent={Type:new Proxy({},{get:function(){return 0}}),};ima.AdsLoader=ima.AdsRequest=ima.AdDisplayContainer=function(){return new Proxy({},{get:function(){return _f}});};ima.settings={__noSuchMethod__:function(){}};google.ima=ima;}


If anyone has suggestions as to how better write script surrogate, please share, I am happy to learn something new :)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:38.0) Gecko/20100101 Firefox/38.0

barbaz
Senior Member
Posts: 9231
Joined: Sat Aug 03, 2013 5:45 pm

Re: Fix for 2mdn.net

Post by barbaz » Tue Jun 02, 2015 10:11 pm

Thanks for that.
Yeah, that's not the best way to do it. Please test this and let us know if it works:

Code: Select all

[broken suggestion deleted]
*Always* check the changelogs BEFORE updating that important software!
-

saaib
Posts: 3
Joined: Sat May 23, 2015 6:59 pm

Re: Fix for 2mdn.net

Post by saaib » Tue Jun 02, 2015 11:08 pm

Your suggestion did not work, but it did get me interested in JavaScript Proxies :D
After reading a bit about what they do I came up with a working solution:

Code: Select all

if('Proxy' in window){ let _f=function(){}; google={}; Object.defineProperty(google,'__noSuchMethod__',{configurable:true,enumerable:false,value:_f}); let ima={}; ima.AdsManagerLoadedEvent=ima.AdErrorEvent={Type:new Proxy({},{get:function(){return 0}}),}; ima.settings=new Proxy({},{get:function(){return _f}}); ima.AdsLoader=ima.AdsRequest=ima.AdDisplayContainer=function(){return new Proxy({},{get:function(){return _f}});}; google.ima=ima; }
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:38.0) Gecko/20100101 Firefox/38.0

barbaz
Senior Member
Posts: 9231
Joined: Sat Aug 03, 2013 5:45 pm

Re: Fix for 2mdn.net

Post by barbaz » Wed Jun 03, 2015 12:09 am

saaib wrote:Your suggestion did not work,

Image Oversight on my part. Thanks for correcting that.

saaib wrote:it did get me interested in JavaScript Proxies :D

sort-of-offtopic: you might be interested in viewtopic.php?f=10&t=20676
*Always* check the changelogs BEFORE updating that important software!
-

Post Reply