I am using the exposeFunction-command in the following manner:
await this.page.exposeFunction('foo', function(){ return 'bar'; });
This works as intended and gives me the window.foo-function.
If I call this code again, I get the following error:
Error: Failed to add page binding with name foo: window['foo'] already exists!
This error even persists when navigating with page.goto().
Is there a way to unbind a function exposed by exposeFunction()?
You could change the function stored in the _pageBindings
map. This is quite hacky because you would change an internal variable, but it's the only way to solve this.
await this.page.exposeFunction('foo', function(){ return 'bar'; });
this.page._pageBindings.set('foo', function(){ return 'baz'; });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With