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

feat: add support for content scripts 'all_frames' option #17258

Conversation

@samuelmaddock
Copy link
Member

commented Mar 7, 2019

Description of Change

Adds support for Chrome extension content script option all_frames.

The "all_frames" field allows the extension to specify if JavaScript and CSS files should be injected into all frames matching the specified URL requirements or only into the topmost frame in a tab.

Optional. Defaults to false, meaning that only the top frame is matched.

If specified true, it will inject into all frames, even if the frame is not the topmost frame in the tab. Each frame is checked independently for URL requirements, it will not inject into child frames if the URL requirements are not met.

These changes will only work with the non-sandboxed renderer until #16218 is merged.

Checklist

Release Notes

Notes: Added all_frames support for Chrome extension content scripts.

@samuelmaddock samuelmaddock requested review from zcbenz and MarshallOfSound Mar 7, 2019

@samuelmaddock samuelmaddock referenced this pull request Mar 7, 2019

Closed

Improve browser security #1

5 of 8 tasks complete
@MarshallOfSound
Copy link
Member

left a comment

Blocking pending #16218 and new tests to verify sandbox works with this 👍

@samuelmaddock samuelmaddock referenced this pull request Mar 7, 2019

Merged

fix: support chrome extensions in sandboxed renderer #16218

5 of 5 tasks complete

@samuelmaddock samuelmaddock force-pushed the samuelmaddock:chrome-extension/content-script-all-frames branch from 9a98328 to 174e9bc Mar 8, 2019

@samuelmaddock samuelmaddock force-pushed the samuelmaddock:chrome-extension/content-script-all-frames branch from fe728f1 to 4fdcdfe Mar 8, 2019

merged content script tests
'all_frames' test now runs on all variants of sandbox/contentIsolation configurations :D

@samuelmaddock samuelmaddock force-pushed the samuelmaddock:chrome-extension/content-script-all-frames branch from 4fdcdfe to 99451b0 Mar 8, 2019

@electron-cation electron-cation bot removed the new-pr 🌱 label Mar 8, 2019

@MarshallOfSound
Copy link
Member

left a comment

Looks good, thanks for the tests 👍

@MarshallOfSound MarshallOfSound merged commit 8ee153d into electron:master Mar 8, 2019

8 of 9 checks passed

appveyor: win-ia32-testing-pr AppVeyor build failed
Details
Artifact Comparison No Changes
Details
Semantic Pull Request ready to be squashed
Details
WIP Ready for review
Details
appveyor: win-x64-testing-pr AppVeyor build succeeded
Details
build-linux Workflow: build-linux
Details
build-mac Workflow: build-mac
Details
lint Workflow: lint
Details
release-notes Release notes found
@release-clerk

This comment has been minimized.

Copy link

commented Mar 8, 2019

Release Notes Persisted

Added all_frames support for Chrome extension content scripts.

@samuelmaddock samuelmaddock deleted the samuelmaddock:chrome-extension/content-script-all-frames branch Mar 9, 2019

@erez12

This comment has been minimized.

Copy link

commented Apr 3, 2019

@samuelmaddock on Electron 6.0.0-nightly.20190311 i cant get my extension to run on all frames.
I have the following setup:

Extension manifest:

{
	"name": "content-script-test",
	"version": "1.0",
	"content_scripts": [{
		"matches": ["<all_urls>"],
		"js": [
			"test_working_content_document_start.js"
		],
		"run_at": "document_start",
		"all_frames": true
	}],
	"manifest_version": 2
}

test_working_content_document_start.js:
console.log(window.location.href);

Electron main:

const { BrowserWindow } = require('electron');
BrowserWindow.addExtension('../my_extension_folder');

let win = new BrowserWindow({
     width: 1600,
     height: 1000,
        
});

win.loadURL('https://www.w3schools.com/html/html_iframe.asp')

On chrome im getting multiple logs of the iframe urls. On electron im only getting printout of the top frame.

had a look at nightly#6.0.0-nightly.20190311 source (https://github.com/electron/electron/tree/b43e4b8e0e93eedd466a2794e02e0452f27407d9) and it seems that both this #17258 and #16218 are there.

What am i missing ?

@samuelmaddock

This comment has been minimized.

Copy link
Member Author

commented Apr 6, 2019

@erez12: try adding the nodeIntegrationInSubFrames property to your webPreferences. It's required to enable script injection in subframes. The work in #17440 will eventually deprecate the need for this.

@erez12

This comment has been minimized.

Copy link

commented Apr 7, 2019

@samuelmaddock Great! That solved the issue but raised more issues...
Now when i send a message from content script to background i dont get the frameId:

content.js:
chrome.runtime.sendMessage({topic: "page_load"})

background.js:

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    if ( request.topic === "page_load") {
        console.log(sender.frameId) // This is undefined
    }
});

Since there is a known issue in Electron with sendResponse not working, i wanted to use the tabs API to respond to the sender but i can't send the message to a specific frame...

Seems there is more stuff to do for full extensions support. Is there any time frame for #17440 ?

Kiku-Reise added a commit to Kiku-Reise/electron that referenced this pull request May 16, 2019

feat: add support for content scripts 'all_frames' option (electron#1…
…7258)

* feat: add support for content scripts 'all_frames' option

* merged content script tests

'all_frames' test now runs on all variants of sandbox/contentIsolation configurations :D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.