Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot remove event listeners because rollbar wraps them #5

Open
CodeWithOz opened this issue Jan 12, 2021 · 3 comments
Open

Cannot remove event listeners because rollbar wraps them #5

CodeWithOz opened this issue Jan 12, 2021 · 3 comments

Comments

@CodeWithOz
Copy link

I've noticed that using .removeEventListener on my event listeners no longer works because the actual function that is submitted to addEventListener is a function wrapper from Rollbar. Put simply, this doesn't work:

const handler = e => e.target;
// the event listener gets set correctly
node.addEventListener('click', handler, false);
// but I can no longer remove it because this doesn't work, clicking the node still triggers the handler
node.removeEventListener('click', handler, false);

I can see in my debugger that the actual handler is a rollbar wrapped function, and I don't have a way of getting a reference to that function, so I can't pass it to removeEventListener. What's the way out here?

@waltjones
Copy link
Contributor

waltjones commented Jan 12, 2021

There isn't a config option in the Cordova SDK currently, but this work around should work.

In your js initialization, set captureUncaught: false:

window.Rollbar = new rollbar({
            accessToken: "YOUR_CLIENT_TOKEN",
            captureUncaught: false, // set false for constructor
            captureUnhandledRejections: true,
        })

Then you should be able to enable captureUncaught in rollbarConfigure() without the wrappers being added to the event listeners.

window.Rollbar.configure({ captureUncaught: true }) // enable captureUncaught without event listener wrappers

@CodeWithOz
Copy link
Author

Thanks I'll try that 👍 .

@waltjones
Copy link
Contributor

Quick note, maybe it's obvious. configure is called on the instance: window.Rollbar.configure({ captureUncaught: true }).

I'll update my example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants