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

fix: listeners out of limit warning #12841

Merged
merged 1 commit into from May 8, 2018

Conversation

Projects
None yet
5 participants
@biuuu
Contributor

biuuu commented May 7, 2018

When the Chrome Extension has too many content scripts (above default 10 counts), there will be a warning:
warning: possible EventEmitter memory leak detected. 11 listeners added.

@biuuu biuuu requested a review from electron/reviewers as a code owner May 7, 2018

@welcome

This comment has been minimized.

Show comment
Hide comment
@welcome

welcome bot May 7, 2018

💖 Thanks for opening this pull request! 💖

We use
semantic commit messages
to streamline the release process. Before your pull request can be merged, you
should update your pull request title to start with a semantic prefix,
OR prefix at least one of your commit messages.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

welcome bot commented May 7, 2018

💖 Thanks for opening this pull request! 💖

We use
semantic commit messages
to streamline the release process. Before your pull request can be merged, you
should update your pull request title to start with a semantic prefix,
OR prefix at least one of your commit messages.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@biuuu biuuu changed the title from fix listeners out of limit warning to fix: listeners out of limit warning May 7, 2018

@codebytere

This comment has been minimized.

Show comment
Hide comment
@codebytere

codebytere May 7, 2018

Member

@biuuu it's not clear exactly what the purpose of this code is, can you please explain further?

Member

codebytere commented May 7, 2018

@biuuu it's not clear exactly what the purpose of this code is, can you please explain further?

@biuuu

This comment has been minimized.

Show comment
Hide comment
@biuuu

biuuu May 7, 2018

Contributor

@codebytere
I found some Chrome Extension didn't work in BrowserWindow and got the following error:
qq 20180507234223

for (const {url, code} of script.js) {
const fire = runContentScript.bind(window, extensionId, url, code)
if (script.runAt === 'document_start') {
process.once('document-start', fire)
} else if (script.runAt === 'document_end') {
process.once('document-end', fire)
} else {
document.addEventListener('DOMContentLoaded', fire)
}
}

The problem is that if an extension contains more than 10 content scripts, this code will add multiple listeners at the same time.

But now I understand that this may not be the real reason why extension cannot run.
It seems that some of the extension define the function directly at the top of some content script and call it directly in other content scripts.
This PR just removed the warning.
Should I add an issue?

Contributor

biuuu commented May 7, 2018

@codebytere
I found some Chrome Extension didn't work in BrowserWindow and got the following error:
qq 20180507234223

for (const {url, code} of script.js) {
const fire = runContentScript.bind(window, extensionId, url, code)
if (script.runAt === 'document_start') {
process.once('document-start', fire)
} else if (script.runAt === 'document_end') {
process.once('document-end', fire)
} else {
document.addEventListener('DOMContentLoaded', fire)
}
}

The problem is that if an extension contains more than 10 content scripts, this code will add multiple listeners at the same time.

But now I understand that this may not be the real reason why extension cannot run.
It seems that some of the extension define the function directly at the top of some content script and call it directly in other content scripts.
This PR just removed the warning.
Should I add an issue?

@MarshallOfSound

This comment has been minimized.

Show comment
Hide comment
@MarshallOfSound

MarshallOfSound May 7, 2018

Member

@biuuu We don't technically support chrome extensions, we barely support chrome devtools extensions. This PR will remove a warning but won't fix the underlying issue which is probably a missing chrome.* API

Member

MarshallOfSound commented May 7, 2018

@biuuu We don't technically support chrome extensions, we barely support chrome devtools extensions. This PR will remove a warning but won't fix the underlying issue which is probably a missing chrome.* API

@zcbenz

Having one single listener looks better in design and performance than adding a listener for every content script. I'm 👍 on this change.

Show outdated Hide outdated lib/renderer/content-scripts-injector.js
@zcbenz

This comment has been minimized.

Show comment
Hide comment
@zcbenz

zcbenz May 8, 2018

Contributor

@biuuu We don't technically support chrome extensions, we barely support chrome devtools extensions. This PR will remove a warning but won't fix the underlying issue which is probably a missing chrome.* API

This warning is because we are adding new event listeners for every content script, it means we have a problem in our code instead of the extension's code.

Contributor

zcbenz commented May 8, 2018

@biuuu We don't technically support chrome extensions, we barely support chrome devtools extensions. This PR will remove a warning but won't fix the underlying issue which is probably a missing chrome.* API

This warning is because we are adding new event listeners for every content script, it means we have a problem in our code instead of the extension's code.

@MarshallOfSound

This comment has been minimized.

Show comment
Hide comment
@MarshallOfSound

MarshallOfSound May 8, 2018

Member

@zcbenz Yeah sorry my comment wasn't clear, this PR will fix the warning, but the warning isn't why the chrome extension this user is trying to add isn't working. It's just a warning from node to avoid memory leaks and such.

Member

MarshallOfSound commented May 8, 2018

@zcbenz Yeah sorry my comment wasn't clear, this PR will fix the warning, but the warning isn't why the chrome extension this user is trying to add isn't working. It's just a warning from node to avoid memory leaks and such.

fix: listeners out of limit warning
When the Chrome Extension has too many content scripts (above default
10 counts), there will be a warning: possible EventEmitter memory leak
detected. 11 listeners added.
@ckerr

ckerr approved these changes May 8, 2018

This LGTM, Using 1 listener instead of N is an improvement, regardless of how much we support (or don't support) extensions 😃

@ckerr

This comment has been minimized.

Show comment
Hide comment
@ckerr

ckerr May 8, 2018

Member

One question: should this be backported to 2.0.x? This looks nonbreaking to me, but instead of adding the target/2-0-x label I thought I'd ask anyone here more familiar with the code than me.

Member

ckerr commented May 8, 2018

One question: should this be backported to 2.0.x? This looks nonbreaking to me, but instead of adding the target/2-0-x label I thought I'd ask anyone here more familiar with the code than me.

@zcbenz

zcbenz approved these changes May 8, 2018

@zcbenz

This comment has been minimized.

Show comment
Hide comment
@zcbenz

zcbenz May 8, 2018

Contributor

Looks good to me to backport.

Contributor

zcbenz commented May 8, 2018

Looks good to me to backport.

@zcbenz zcbenz added the target/2-0-x label May 8, 2018

@zcbenz zcbenz merged commit 86d023b into electron:master May 8, 2018

10 checks passed

WIP ready for review
Details
ci/circleci: electron-linux-arm Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-arm-test Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-arm64 Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-arm64-test Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-ia32 Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-x64 Your tests passed on CircleCI!
Details
ci/circleci: electron-mas-x64 Your tests passed on CircleCI!
Details
ci/circleci: electron-osx-x64 Your tests passed on CircleCI!
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@welcome

This comment has been minimized.

Show comment
Hide comment
@welcome

welcome bot May 8, 2018

Congrats on merging your first pull request! 🎉🎉🎉

welcome bot commented May 8, 2018

Congrats on merging your first pull request! 🎉🎉🎉

@trop

This comment has been minimized.

Show comment
Hide comment
@trop

trop bot May 8, 2018

We have automatically backported this PR to "2-0-x", please check out #12856

trop bot commented May 8, 2018

We have automatically backported this PR to "2-0-x", please check out #12856

@trop trop bot added merged/2-0-x and removed target/2-0-x labels May 8, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment