@@ -177,7 +177,7 @@ class BrowserWindowProxy {
177177export const windowSetup = (
178178 guestInstanceId : number , openerId : number , isHiddenPage : boolean , usesNativeWindowOpen : boolean
179179) => {
180- if ( guestInstanceId == null ) {
180+ if ( ! process . sandboxed && guestInstanceId == null ) {
181181 // Override default window.close.
182182 window . close = function ( ) {
183183 ipcRendererInternal . sendSync ( 'ELECTRON_BROWSER_WINDOW_CLOSE' )
@@ -197,53 +197,57 @@ export const windowSetup = (
197197 return null
198198 }
199199 }
200+ }
200201
201- if ( openerId != null ) {
202- window . opener = getOrCreateProxy ( openerId )
203- }
202+ if ( openerId != null ) {
203+ window . opener = getOrCreateProxy ( openerId )
204204 }
205205
206206 // But we do not support prompt().
207207 window . prompt = function ( ) {
208208 throw new Error ( 'prompt() is and will not be supported.' )
209209 }
210210
211- ipcRendererInternal . on ( 'ELECTRON_GUEST_WINDOW_POSTMESSAGE' , function (
212- _event , sourceId : number , message : any , sourceOrigin : string
213- ) {
214- // Manually dispatch event instead of using postMessage because we also need to
215- // set event.source.
216- //
217- // Why any? We can't construct a MessageEvent and we can't
218- // use `as MessageEvent` because you're not supposed to override
219- // data, origin, and source
220- const event : any = document . createEvent ( 'Event' )
221- event . initEvent ( 'message' , false , false )
222-
223- event . data = message
224- event . origin = sourceOrigin
225- event . source = getOrCreateProxy ( sourceId )
226-
227- window . dispatchEvent ( event as MessageEvent )
228- } )
229-
230- window . history . back = function ( ) {
231- ipcRendererInternal . send ( 'ELECTRON_NAVIGATION_CONTROLLER_GO_BACK' )
211+ if ( ! usesNativeWindowOpen || openerId != null ) {
212+ ipcRendererInternal . on ( 'ELECTRON_GUEST_WINDOW_POSTMESSAGE' , function (
213+ _event , sourceId : number , message : any , sourceOrigin : string
214+ ) {
215+ // Manually dispatch event instead of using postMessage because we also need to
216+ // set event.source.
217+ //
218+ // Why any? We can't construct a MessageEvent and we can't
219+ // use `as MessageEvent` because you're not supposed to override
220+ // data, origin, and source
221+ const event : any = document . createEvent ( 'Event' )
222+ event . initEvent ( 'message' , false , false )
223+
224+ event . data = message
225+ event . origin = sourceOrigin
226+ event . source = getOrCreateProxy ( sourceId )
227+
228+ window . dispatchEvent ( event as MessageEvent )
229+ } )
232230 }
233231
234- window . history . forward = function ( ) {
235- ipcRendererInternal . send ( 'ELECTRON_NAVIGATION_CONTROLLER_GO_FORWARD' )
236- }
232+ if ( ! process . sandboxed ) {
233+ window . history . back = function ( ) {
234+ ipcRendererInternal . send ( 'ELECTRON_NAVIGATION_CONTROLLER_GO_BACK' )
235+ }
237236
238- window . history . go = function ( offset : number ) {
239- ipcRendererInternal . send ( 'ELECTRON_NAVIGATION_CONTROLLER_GO_TO_OFFSET' , + offset )
240- }
237+ window . history . forward = function ( ) {
238+ ipcRendererInternal . send ( 'ELECTRON_NAVIGATION_CONTROLLER_GO_FORWARD' )
239+ }
241240
242- Object . defineProperty ( window . history , 'length' , {
243- get : function ( ) {
244- return ipcRendererInternal . sendSync ( 'ELECTRON_NAVIGATION_CONTROLLER_LENGTH' )
241+ window . history . go = function ( offset : number ) {
242+ ipcRendererInternal . send ( 'ELECTRON_NAVIGATION_CONTROLLER_GO_TO_OFFSET' , + offset )
245243 }
246- } )
244+
245+ Object . defineProperty ( window . history , 'length' , {
246+ get : function ( ) {
247+ return ipcRendererInternal . sendSync ( 'ELECTRON_NAVIGATION_CONTROLLER_LENGTH' )
248+ }
249+ } )
250+ }
247251
248252 if ( guestInstanceId != null ) {
249253 // Webview `document.visibilityState` tracks window visibility (and ignores
0 commit comments