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

Allow us to discover what window opened the current window #24807

Closed
3 tasks done
pushkin- opened this issue Jul 31, 2020 · 2 comments · Fixed by #35140
Closed
3 tasks done

Allow us to discover what window opened the current window #24807

pushkin- opened this issue Jul 31, 2020 · 2 comments · Fixed by #35140

Comments

@pushkin-
Copy link

pushkin- commented Jul 31, 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 a feature request that matches the one I want to file, without success.

Problem Description

When a window is opened, I would like to know what window opened it.

For example if the window with ID 1 triggered a window.open call, I'd like to know that the window with ID 2 was opened by window 1.

Currently, the referrer information passed to the new-window handler only contains a URL property (which in my case is always '' for some reason).

Proposed Solution

Can the referrer argument get an additional property that tells us the ID of the window that's making the window.open call?
(I'm not sure how this will fit into the new setWindowOpenOverride mechanism)

Alternatively, maybe the BrowserWindow class can have an openerWindowId type of property that gives us this information. That would maybe be preferable.

Alternatives Considered

I can work around it by passing in the window ID like so:

// ... inside of the browser-window-created handler
window.webContents.addListener("new-window", function (): void {
	[].push.call(arguments, window.id);
	newWindowHandler.apply(null, arguments);
});
@Plastikmensch
Copy link

If I'm understanding correctly, you can already do that by combining the browser-window-created and new-window event
Example:

app.on('browser-window-created', (event, win) => {
    win.webContents.on('new-window', () => {
        console.log('${win.id} opened a new window`)
    }
}

You can also get the id of the new window by creating it yourself.
Opening new windows by default is not a good idea.

@pushkin-
Copy link
Author

pushkin- commented Aug 3, 2020

@Plastikmensch Yes, that's solution I proposed at the end. But I would prefer a simple property that would tell me the opener window rather than doing what I did.

In my situation, I do want to allow windows to open windows by default.

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

Successfully merging a pull request may close this issue.

5 participants