(timeout: number = DEFAULT_INITIALIZING_TIMEOUT)
| 43 | } |
| 44 | |
| 45 | initializeWebview(timeout: number = DEFAULT_INITIALIZING_TIMEOUT) { |
| 46 | this.webview = document.createElement('webview') |
| 47 | if (!this.webview) return |
| 48 | |
| 49 | this.webview.addEventListener('destroyed', () => { |
| 50 | this.destroyWebview() |
| 51 | }) |
| 52 | |
| 53 | // TODO: THis dupe can be removed |
| 54 | this.webview.addEventListener('destroyed', () => { |
| 55 | this.destroyWebview() |
| 56 | }) |
| 57 | |
| 58 | this.webview.addEventListener('console-message', (e) => { |
| 59 | this.consoleMessages.push(e.message) |
| 60 | }) |
| 61 | |
| 62 | this.webview.addEventListener('dom-ready', () => { |
| 63 | this.webview?.setAudioMuted(true) |
| 64 | }) |
| 65 | |
| 66 | this.webview.addEventListener('ipc-message', (event) => { |
| 67 | if (event.channel !== 'webview-page-event') return |
| 68 | |
| 69 | const eventType = event.args[0] as WebViewEventSendNames |
| 70 | const eventData = event.args[1] |
| 71 | |
| 72 | if (!eventType) return |
| 73 | |
| 74 | if (eventType === WebViewEventSendNames.DetectedApp) { |
| 75 | if (this.appDetectionCallback) { |
| 76 | this.appDetectionCallback(eventData.appName) |
| 77 | } |
| 78 | } else if (eventType === WebViewEventSendNames.DetectedResource) { |
| 79 | if (this.resourceDetectionCallback) { |
| 80 | this.resourceDetectionCallback(eventData) |
| 81 | } |
| 82 | } |
| 83 | }) |
| 84 | |
| 85 | this.webview.style.width = '100%' |
| 86 | this.webview.style.height = '100%' |
| 87 | this.webview.style.position = 'fixed' |
| 88 | this.webview.style.top = '0' |
| 89 | this.webview.style.left = '0' |
| 90 | this.webview.style.zIndex = '999999' |
| 91 | this.webview.style.backgroundColor = 'white' |
| 92 | this.webview.style.border = 'none' |
| 93 | this.webview.style.overflow = 'hidden' |
| 94 | this.webview.style.opacity = '0' |
| 95 | this.webview.style.pointerEvents = 'none' |
| 96 | |
| 97 | this.webview.setAttribute('data-webview-extractor', 'true') |
| 98 | this.webview.src = this.url |
| 99 | this.webview.partition = this.partition |
| 100 | this.webview.webpreferences = |
| 101 | 'autoplayPolicy=document-user-activation-required,contextIsolation=true,nodeIntegration=false,sandbox=true,webSecurity=true' |
| 102 | // webviews needed for extracting stuff don't need to create windows |
no test coverage detected