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

Events are only listened in the same context that requested them #1

Open
bfred-it opened this issue Jul 1, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@bfred-it
Copy link
Owner

commented Jul 1, 2019

This polyfill will exclusively work if permissions are requested/removed from the same page where the listener is. That means, if you run chrome.permissions.request in the background page, only the same exact page will receive the event.

This works

// In background.js
chrome.contextMenus.onClicked.addListener(() => {
  chrome.permissions.request({
    origins: [`https://youtube.com/*`]
  });
});

// ALSO in background.js
chrome.permissions.onAdded.addListener(({ origins }) => {
  if (!origins || origins.length === 0) {
    return;
  }

  console.log("New origins!", origins);
});

This doesn't

If you want to request from options.html or popup.html, it won't work.

// In options.html
document.querySelector(".add-youtube").addEventListener("click", () => {
  chrome.permissions.request({
    origins: [`https://youtube.com/*`]
  });
});
// In background.js
chrome.permissions.onAdded.addListener(({ origins }) => {
  if (!origins || origins.length === 0) {
    return;
  }

  console.log("New origins!", origins);
});

Add your interest in this issue or send a PR to add support via runtime.sendMessage

@bfred-it bfred-it added the enhancement label Jul 3, 2019

@bfred-it bfred-it referenced a pull request that will close this issue Jul 3, 2019

Draft

Handle permission changes across contexts #4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.