react-new-window icon indicating copy to clipboard operation
react-new-window copied to clipboard

onBlock is never called

Open gnekoz opened this issue 2 years ago • 1 comments

In case the browser settings block the opening of a new popup/tab an error is raised and the onBlock callback is never invoked. The cause is the creation of the div right after the window creation:

    // Open a new window.
    this.window = window.open(url, name, toWindowFeatures(features))
    this.container = this.window.document.createElement('div')

In case of browser blocking the window opening this.window will be undefined and the second line will fail:

TypeError: Cannot read properties of null (reading 'document')
    at NewWindow.openChild (new-window.js:236:32)
    at NewWindow.componentDidMount (new-window.js:191:9)
    at commitLifeCycles (react-dom.development.js:20664:1)

Also the creation of the div element seems unnecessary since the container property will be set few lines below:

		if (this.window) {
			this.window.document.title = title;

			// Check if the container already exists as the window may have been already open
			this.container = this.window.document.getElementById('new-window-container');

gnekoz avatar Feb 02 '23 17:02 gnekoz

This leads to my web app crashing and the only solution is to not use this otherwise good library.

lfpose avatar Jun 06 '25 19:06 lfpose