mildrenben mildrenben - 1 year ago 220
Javascript Question

Close button opens new chrome store tab on Chrome extension popup

We have a Chrome extension download button on our site.

When you click it, it opens a popup that says 'Add extension', 'Cancel' etc. Popup I'm referring to

The image shows the popup I'm referring to.

It works fine, except for the cancel button opens a new tab and takes you to the plugins chrome store page.

I have no idea why it does this, or how to just get it to cancel.

The js:

chrome.webstore.install(webStoreURL, () => null, (error, errorCode) => {, '_blank');

Any help is much appreciated.

Xan Xan
Answer Source

Well, you indiscriminately try to open the Webstore page on "error". In fact, user clicking Cancel is one of many "error" conditions.

You need to analyze the errorCode to filter that out.

chrome.webstore.install(webStoreURL, () => null, (error, errorCode) => {
   if (errorCode !== "userCanceled") {, '_blank');

Note: as is obvious from the error code list, there are many other conditions that make opening the Web Store page useless. You should re-think this logic.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download