Page 1 of 1

Fix for 2mdn.net

Posted: Tue Jun 02, 2015 10:08 pm
by saaib
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 :)

Re: Fix for 2mdn.net

Posted: Tue Jun 02, 2015 10:11 pm
by barbaz
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]

Re: Fix for 2mdn.net

Posted: Tue Jun 02, 2015 11:08 pm
by saaib
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; }

Re: Fix for 2mdn.net

Posted: Wed Jun 03, 2015 12:09 am
by barbaz
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