| 
									
										
										
										
											2016-09-26 17:40:45 -03:00
										 |  |  | <html> | 
					
						
							|  |  |  | <script type="text/javascript" charset="utf-8"> | 
					
						
							| 
									
										
										
										
											2017-05-01 10:17:15 -03:00
										 |  |  |   function timeout(ms) { | 
					
						
							|  |  |  |     return new Promise((resolve) => { | 
					
						
							|  |  |  |       setTimeout(resolve, ms) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   async function invokeGc () { | 
					
						
							|  |  |  |     // it seems calling window.gc once does not guarantee garbage will be | 
					
						
							|  |  |  |     // collected, so we repeat 10 times with interval of 100 ms | 
					
						
							|  |  |  |     for (let i = 0; i < 10; i++) { | 
					
						
							|  |  |  |       window.gc() | 
					
						
							|  |  |  |       await timeout(100) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-05-15 09:17:07 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const [,test] = window.location.href.split('?') | 
					
						
							|  |  |  |   if (window.opener && test !== 'reload-remote') { | 
					
						
							| 
									
										
										
										
											2016-09-30 08:36:51 -07:00
										 |  |  |     window.callback = () => { | 
					
						
							| 
									
										
										
										
											2016-09-26 17:40:45 -03:00
										 |  |  |       opener.require('electron').ipcRenderer.send('answer', document.body.innerHTML) | 
					
						
							| 
									
										
										
										
											2016-09-30 08:36:51 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-09-26 17:40:45 -03:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2017-05-15 09:17:07 -03:00
										 |  |  |     const {ipcRenderer, remote} = require('electron') | 
					
						
							| 
									
										
										
										
											2016-09-26 17:40:45 -03:00
										 |  |  |     const tests = { | 
					
						
							| 
									
										
										
										
											2017-05-15 09:17:07 -03:00
										 |  |  |       'reload-remote-child': () => { | 
					
						
							|  |  |  |         open(`${location.protocol}//${location.pathname}?reload-remote`) | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       'reload-remote': async () => { | 
					
						
							|  |  |  |         const p = ipcRenderer.sendSync('get-remote-module-path') | 
					
						
							|  |  |  |         const Hello = remote.require(p) | 
					
						
							|  |  |  |         if (!ipcRenderer.sendSync('reloaded')) { | 
					
						
							|  |  |  |           ipcRenderer.send('reload') | 
					
						
							|  |  |  |           return | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         await invokeGc() | 
					
						
							|  |  |  |         ipcRenderer.send('answer', new Hello().say()) | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2018-07-22 00:27:38 +10:00
										 |  |  |       // FIXME: Chromium 67 - getProcessMemoryInfo has been removed | 
					
						
							|  |  |  |       // 'allocate-memory': async () => { | 
					
						
							|  |  |  |       //   await invokeGc() | 
					
						
							|  |  |  |       //   const {privateBytes: bytesBeforeOpen} = process.getProcessMemoryInfo() | 
					
						
							|  |  |  |       //   let w = open('./allocate-memory.html') | 
					
						
							|  |  |  |       //   await invokeGc() | 
					
						
							|  |  |  |       //   const {privateBytes: bytesAfterOpen} = process.getProcessMemoryInfo() | 
					
						
							|  |  |  |       //   w.close() | 
					
						
							|  |  |  |       //   w = null | 
					
						
							|  |  |  |       //   await invokeGc() | 
					
						
							|  |  |  |       //   const {privateBytes: bytesAfterClose} = process.getProcessMemoryInfo() | 
					
						
							|  |  |  |       //   ipcRenderer.send('answer', { | 
					
						
							|  |  |  |       //     bytesBeforeOpen, bytesAfterOpen, bytesAfterClose | 
					
						
							|  |  |  |       //   }) | 
					
						
							|  |  |  |       // }, | 
					
						
							| 
									
										
										
										
											2016-09-26 17:40:45 -03:00
										 |  |  |       'window-events': () => { | 
					
						
							|  |  |  |         document.title = 'changed' | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       'webcontents-stop': () => { | 
					
						
							|  |  |  |         stop() | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       'webcontents-events': () => { | 
					
						
							|  |  |  |         addEventListener('load', () => { | 
					
						
							|  |  |  |           location.hash = 'in-page-navigate' | 
					
						
							|  |  |  |           setTimeout(() => { | 
					
						
							|  |  |  |             location.reload() | 
					
						
							|  |  |  |           }, 50) | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       'exit-event': () => { | 
					
						
							|  |  |  |         process.on('exit', () => { | 
					
						
							|  |  |  |           ipcRenderer.send('answer', location.href) | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |         location.assign('http://www.google.com') | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       'window-open': () => { | 
					
						
							|  |  |  |         addEventListener('load', () => { | 
					
						
							|  |  |  |           popup = open(window.location.href, 'popup!', 'top=60,left=50,width=500,height=600') | 
					
						
							|  |  |  |           popup.addEventListener('DOMContentLoaded', () => { | 
					
						
							|  |  |  |             popup.document.write('<h1>scripting from opener</h1>') | 
					
						
							|  |  |  |             popup.callback() | 
					
						
							|  |  |  |           }, false) | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       'window-open-external': () => { | 
					
						
							|  |  |  |         addEventListener('load', () => { | 
					
						
							|  |  |  |           ipcRenderer.once('child-loaded', (e) => { | 
					
						
							|  |  |  |             try { | 
					
						
							|  |  |  |               let childDoc = popup.document | 
					
						
							|  |  |  |             } catch (e) { | 
					
						
							|  |  |  |               ipcRenderer.send('answer', e.message) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  |           popup = open('http://www.google.com/#q=electron', '', 'top=65,left=55,width=505,height=605') | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       'verify-ipc-sender': () => { | 
					
						
							|  |  |  |         popup = open() | 
					
						
							|  |  |  |         ipcRenderer.once('verified', () => { | 
					
						
							|  |  |  |           ipcRenderer.send('parent-answer') | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |         popup.ipcRenderer.once('verified', () => { | 
					
						
							|  |  |  |           popup.ipcRenderer.send('child-answer') | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2018-06-13 04:38:31 -03:00
										 |  |  |         ipcRenderer.send('parent-ready') | 
					
						
							|  |  |  |         popup.ipcRenderer.send('child-ready') | 
					
						
							| 
									
										
										
										
											2016-09-26 17:40:45 -03:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     addEventListener('unload', () => { | 
					
						
							|  |  |  |       if (window.popup) | 
					
						
							|  |  |  |         popup.close() | 
					
						
							|  |  |  |     }, false) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-30 08:36:51 -07:00
										 |  |  |     if (tests.hasOwnProperty(test)) | 
					
						
							|  |  |  |       tests[test]() | 
					
						
							| 
									
										
										
										
											2016-09-26 17:40:45 -03:00
										 |  |  |   } | 
					
						
							|  |  |  | </script> | 
					
						
							|  |  |  | </html> |