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

webContents.sendToFrame does not always work #27066

Closed
3 tasks done
t57ser opened this issue Dec 17, 2020 · 3 comments
Closed
3 tasks done

webContents.sendToFrame does not always work #27066

t57ser opened this issue Dec 17, 2020 · 3 comments

Comments

@t57ser
Copy link
Contributor

t57ser commented Dec 17, 2020

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    • 11.0.4, 11.1.0 (please also check additional information)
  • Operating System:
    • Windows 10
  • Last Known Working Electron version:
    • ?

Expected Behavior

Messages should always reach the frame

Actual Behavior

Sometimes it can happen that using the correct frameId will not send any messages to the frame

To Reproduce

main.js

const electron = require("electron");
const path = require("path");

const init = () => {
	let browserWindow = new electron.BrowserWindow({
		show: true,
		webPreferences: {
			preload: path.join(electron.app.getAppPath(), "/preload.js"),
			webviewTag: true,
			plugins: true,
			nodeIntegrationInSubFrames: true,
			sandbox: true,
			contextIsolation: false,
			nodeIntegration: false,
		}
	});

	browserWindow.loadURL(path.join(electron.app.getAppPath(), "index.html"));

	setInterval(() => {
		const webContent = electron.webContents.fromId(browserWindow.webContents.id);
		webContent.sendToFrame(4, "asynchronous-reply", "hi" + Math.random());
		webContent.sendToFrame(5, "asynchronous-reply", "hi" + Math.random());
	}, 3000);
};

electron.app.on("ready", () => {
	init();
});

preload.js

const electron = require("electron");
console.log(electron.webFrame.routingId, global.window === global.top);
if (global.window !== global.top) {
	electron.ipcRenderer.on("asynchronous-reply", (res, obh) => {
		console.log(obh);
	});
}

index.html

<!DOCTYPE html>
<html>
<body>
    <iframe src="http://localhost:9458"/>
</body>
<script>
</script>
</html>

It looks like that whenever the frameId is 4, only a single message reaches the frame then it stops working (see screenshots), when the frameId is 5 it always receives all messages.
I manage to reproduce it after a couple of tries, happens around 1/5 times.

Screenshots

grafik
grafik

Additional Information

I noticed that I didn't host anything at localhost:9458, after hosting an empty page it seemed to work for 11.0.4
but when trying the same thing in 11.1.0, I never receive any message.

I also checked with 10.1.7 -> working and 10.2.0 -> not working.
Looking at the release notes I would assume #26927 caused this.

@t57ser
Copy link
Contributor Author

t57ser commented Dec 17, 2020

I checked the commit #26875 and saw that:
Out-of-process frames can be specified by passing a pair of numbers
[processId, frameId].
This is working, but would be good to have it documented
https://www.electronjs.org/docs/api/web-contents#contentssendtoframeframeid-channel-args
states [number,number] but not what these are

@t57ser t57ser closed this as completed Dec 17, 2020
@nornagon
Copy link
Member

@t57ser
Copy link
Contributor Author

t57ser commented Dec 17, 2020

Yes but it does not mention anything about the processId or when to use [processId, frameId] instead of just frameId or that the order in the array has to be [processId, frameId]
It would be good to document what was mentioned in the commit, i.e.

Using frameId will only target same-process frames by default.
Out-of-process frames can be specified by passing a pair of numbers [processId, frameId]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants