8000 fix: support chrome extensions in sandboxed renderer by samuelmaddock · Pull Request #16218 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: support chrome extensions in sandboxed renderer #16218

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

Conversation

samuelmaddock
Copy link
Member
@samuelmaddock samuelmaddock commented Dec 30, 2018

Description of Change

The sandboxed renderer doesn't currently load any content scripts included with chrome extensions. A few changes were needed to fix this:

  • Add content-script-injector.js to lib/sandboxed_renderer/init.js
  • Use the correct reference to getRenderProcessPreferences in content-script-injector.js (not bound to process in sandboxed lib).
  • Emit document-start and document-end events in sandboxed renderer.

Content scripts don't currently work in subframes when context isolation is enabled. #16804 will need to be fixed first.

Checklist

  • PR description included and stakeholders cc'd
  • npm test passes
  • tests are changed or added
  • PR title follows semantic commit guidelines
  • PR release notes describe the change in a way relevant to app-developers

Release Notes

Notes: Fixed Chrome extension content scripts not loading in sandboxed renderer.

@welcome
Copy link
welcome bot commented Dec 30, 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.

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.

@samuelmaddock samuelmaddock changed the title fix: support chrome extensions in sandboxed renderer [wip] fix: support chrome extensions in sandboxed renderer Dec 31, 2018
@samuelmaddock samuelmaddock force-pushed the sandboxed-renderer-chrome-extensions branch from 5f700df to d70ccaf Compare February 1, 2019 23:52
Copy link
Contributor
@miniak miniak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure it works with context isolation

@samuelmaddock samuelmaddock force-pushed the sandboxed-renderer-chrome-extensions branch from f666408 to da677d3 Compare February 8, 2019 00:47
@samuelmaddock
Copy link
Member Author
samuelmaddock commented Feb 8, 2019

Currently blocked by #16746 for writing tests.

@samuelmaddock samuelmaddock changed the title [wip] fix: support chrome extensions in sandboxed renderer fix: support chrome extensions in sandboxed renderer Feb 8, 2019
@samuelmaddock
Copy link
Member Author

Builds seem to be failing due to unrelated tests. The added content script tests run and pass though.

@MarshallOfSound
Copy link
Member

Builds seem to be failing due to unrelated tests. The added content script tests run and pass though.

They won't be unrelated, the same 13 tests fail on all 3 platforms. My guess is you've included a file (content-scripts-injector) in the sandbox bundle that includes files further down the chain that aren't sandbox compatible. Can you look into those failures?

@samuelmaddock
Copy link
Member Author

My guess is you've included a file (content-scripts-injector) in the sandbox bundle that includes files further down the chain that aren't sandbox compatible.

@MarshallOfSound This might be accurate and #16686 has potential to fix this.

@samuelmaddock samuelmaddock force-pushed the sandboxed-renderer-chrome-extensions branch from cad1ba0 to 3deed89 Compare February 11, 2019 00:30
} catch (error) {
// TODO(samuelmaddock): Run scripts in isolated world, see chromium script_injection.cc
console.error(`Error running content script JavaScript for '${extensionId}'`) 10000
console.error(error)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An error will be thrown when a CSP is set with 'unsafe-eval'. runInThisContext is a wrapper around eval.

@samuelmaddock samuelmaddock force-pushed the sandboxed-renderer-chrome-extensions branch 2 times, most recently from 3be93e6 to 78a2d75 Compare February 20, 2019 18:08
@MarshallOfSound
Copy link
Member

Can you rebase on master now that #17165 has landed and add a test for subframes 👍

Copy link
Member
@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️

@samuelmaddock samuelmaddock force-pushed the sandboxed-renderer-chrome-extensions branch from 78a2d75 to 2fdc8cf Compare March 7, 2019 22:55
@samuelmaddock
Copy link
Member Author

@MarshallOfSound if you want to merge this, i can go ahead and integrate the all_frames test in #17258. this will cover testing subframes.

@MarshallOfSound
Copy link
Member

i can go ahead and integrate the all_frames test in #17258. this will cover testing subframes.

Sounds good to me 👍

6D47
Copy link
Member
@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid Work 💯

@MarshallOfSound MarshallOfSound added the semver/minor backwards-compatible functionality label Mar 8, 2019
@MarshallOfSound MarshallOfSound merged commit 42b7b25 into electron:master Mar 8, 2019
@release-clerk
Copy link
release-clerk bot commented Mar 8, 2019

Release Notes Persisted

Added support for Chrome extension content scripts in sandboxed renderers.

@samuelmaddock samuelmaddock deleted the sandboxed-renderer-chrome-extensions branch March 8, 2019 14:25
kiku-jw pushed a commit to kiku-jw/electron that referenced this pull request May 16, 2019
* Add content script injector to sandboxed renderer

* Fix 'getRenderProcessPreferences' binding to the wrong object

* Pass getRenderProcessPreferences to content-scripts-injector

* Emit document-start and document-end  events in sandboxed renderer

* Use GetContext from RendererClientBase

* Prevent script context crash caused by lazily initialization

* Remove frame filtering logic for onExit callback

Since we're keeping track of which frames we've injected the bundle into, this logic is redundant.

* Add initial content script tests

* Add contextIsolation variants to content script tests

* Add set include

* Fix already loaded extension error

* Add tests for content scripts 'run_at' options

* Catch script injection eval error when CSP forbids it

This can occur in a rendered sandbox when a CSP is enabled. We'll need to switch to using isolated worlds to fix this.

* Fix content script tests not properly cleaning up extensions

* Fix lint and type errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/minor backwards-compatible functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0