(opts: WebViewAdOptions)
| 23 | private _historyCurrentHref = ""; |
| 24 | |
| 25 | constructor(opts: WebViewAdOptions) { |
| 26 | opts.adUnitId = ""; |
| 27 | super(opts); |
| 28 | this._adsense = opts.adsense; |
| 29 | this._src = |
| 30 | opts.src || |
| 31 | "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"; |
| 32 | |
| 33 | // biome-ignore lint/suspicious/noExplicitAny: <explanation> |
| 34 | const win = <any>window; |
| 35 | if ( |
| 36 | typeof win.gmaSdk?.getQueryInfo === "function" || |
| 37 | typeof win.webkit?.messageHandlers?.getGmaQueryInfo?.postMessage === |
| 38 | "function" || |
| 39 | typeof win.webkit?.messageHandlers?.getGmaSig?.postMessage === "function" |
| 40 | ) { |
| 41 | const html = `<script async src="${this._src}" crossorigin="anonymous"></script> |
| 42 | |
| 43 | ${ |
| 44 | opts.npa |
| 45 | ? "<script>(window.adsbygoogle = window.adsbygoogle || []).requestNonPersonalizedAds = 1</script>" |
| 46 | : "" |
| 47 | } |
| 48 | |
| 49 | <script> |
| 50 | (window.adsbygoogle = window.adsbygoogle || []).push({google_ad_client: "${ |
| 51 | this._adsense |
| 52 | }", enable_page_level_ads: true, overlays: false}); |
| 53 | </script> |
| 54 | `; |
| 55 | const div = document.createElement("div"); |
| 56 | div.innerHTML = html; |
| 57 | document.head.appendChild(div); |
| 58 | this.nodeScriptReplace(div); |
| 59 | this._loaded = true; |
| 60 | } else { |
| 61 | console.error("WebView does not appear to be setup correctly"); |
| 62 | } |
| 63 | |
| 64 | document.addEventListener("pause", () => { |
| 65 | this._historyCurrentHref = this.historyCurrentHref(); |
| 66 | this.historyRestoreOriginalHref(); |
| 67 | }); |
| 68 | |
| 69 | document.addEventListener("resume", () => { |
| 70 | if (this._historyCurrentHref) { |
| 71 | this.historyReplaceState(this._historyCurrentHref); |
| 72 | } |
| 73 | }); |
| 74 | } |
| 75 | |
| 76 | public addAd(options: { |
| 77 | element: HTMLElement; |
nothing calls this directly
no test coverage detected