external js - gethooks remove conflict - Uncaught TypeError: Cannot assign to read only property 'remove' of object '[object Array]'
Type of issue
bug
Description
maybe a namespace thing? under certain circumstances external js does something that prebid doesn't like in the remove of objects in the getHooks function deep/hard to reproduce but simple in concept - other javascript has messed with the objects being removed in the getHooks function inside prebid.js -- maybe added objects or altered objects that prebid expected to have a certain format -- i'd guess that some simple try/catch logic around the remove itself could avoid this error
Steps to reproduce
this is a pretty convoluted thing to reproduce since it relies on some external javascript stepping on the hooked objects of a page - but (see test pages below) i have two test pages - one with the error and one without - should be pretty easy to see whats going on given that
Test page
example of broken: http://platform.gourmetads.com/rgtest/www.raiseyourgarden.com/i4.html?pbjs_debug=true
example working: http://platform.gourmetads.com/rgtest/www.raiseyourgarden.com/i3.html?pbjs_debug=true
Expected results
prebid should not error
Actual results
on the broken page - the external weebly javascript main.js has done something to the objects that the remove is trying to remove in its foreach - because of this prebid itself errors - maybe a try.catch coulld avoid this?
========
Uncaught TypeError: Cannot assign to read only property 'remove' of object '[object Array]'
at assign ()
at Proxy.getHooks (prebid_v3_gourmetads_ga.js:3)
at t.d (prebid_v3_gourmetads_ga.js:3)
at Object.194 (prebid_v3_gourmetads_ga.js:30)
at f (prebid_v3_gourmetads_ga.js:3)
at Object.193 (prebid_v3_gourmetads_ga.js:30)
at f (prebid_v3_gourmetads_ga.js:3)
at window.ga_pbjsChunk (prebid_v3_gourmetads_ga.js:3)
at prebid_v3_gourmetads_ga.js:30
Platform details
we are using http://bcdn.grmtas.com/js/prebid_v3_gourmetads_ga.js which is /* prebid.js v3.16.0-pre Updated : 2020-04-14 */
the issue happens on WEEBLY sites which are using their screen editing/config software and introducing some external js which is corrupting the objects that prebid is trying to 'remove' in the getHooks action
Other information
this is not a direct prebid problem but rather weebly messing up the environment that prebid is running in causing it to error when trying to construct an auction - end result is that prebid does not get to bid
the error itself is inside the getHooks part of prebid and seems to be related to it trying to remove objects that were probably created by the weebly mess - possible solution to add some kind of try/catch around the remove inside the getHook action?

so as i suspected this was addressible with a try catch I chased the error line down to this npm module (being pulled into the prebid build)
node_modules/fun-hooks/no-eval/index.js
as fun-hooks was at the latests 0.9.8
I implemented this try/catch around line 203 of that file
============= console.log(hooks); try { return assign(hooks, { remove: function() { hooks.forEach(function(entry) { entry.remove(); }); return this; } }); } catch(e) { return true; }}, removeAll: function() { return this.getHooks().remove(); } };
================
simply returning true if the assignment failed instead of trying to assign a remove function to the object
worth noting that when the issue happens the object list itself was empty ("hooks" was the object) - observed this in the console.log
so in effect it was trying to assign a remove action to an empty object at this point and that was what was blowing things up
speculation that something in the weebly js was clearing that hookable object list during some operations of their own and prebid (fun-hooks) just got stomped because something it expected to be initialized was not
this could probably also be addressed in prebid itself by testing that hookable set is in fact initialized but this hack was more direct and i dont myself want to mess too much with prebid itself even if it would 'protect' it better that way.
so i'm going to close this but the devs might want to look into the situation anyway as a protective measure - hopefully this will help someone else if they are doing prebid on weebly sites and run into a similar error (note: not all weebly sites had the issue so some combination of options/settings in their screen editing js is proably to blame and its questionable if its a global issue or just the result of them clearing those hooks under certain circumstances/options/settings)
Thanks for your investigation @brent-gourmetads
This issue comes from something on your page modifying Array.prototype and adding a readonly remove property to it. This causes any direct assignments to any array instance (like ([]).remove = <whatever> in strict mode ) or through Object.assign to throw a TypeError. That's a pretty bad thing to do and has the potential to cause bugs with lots of code, not just Prebid.js and fun-hooks.
There's really no way to make it work in fun-hooks without changing the API, which I'm not going to do. But I did wrap it in a try ... catch and log a console.error rather than throwing. It still has the potential to cause bugs if someone tries to use the remove property that can never be created, but I prefer failing later when someone tries to use it over failing up front. Thanks for pointing this out, I've published a patch to npm with this change.