Closed heyman closed 3 years ago
I currently use the following monkey patch to fix this issue without using a forked version:
import { isIOS } from "@nativescript/core";
const WebViewExt = require("@nota/nativescript-webview-ext").WebViewExt;
export class FixedWebViewExt extends WebViewExt {
disposeNativeView() {
if (isIOS) {
this.wkWebViewConfiguration.userContentController.removeScriptMessageHandlerForName("nsBridge");
this.wkWebViewConfiguration = null;
}
super.disposeNativeView();
}
}
Thank you very much for the contribution. It has been published with v7.0.2
Great! Thank you very much for a very useful plugin :)!
PR Checklist
I was not able to run the test suite using the instructions in the README (got a whole bunch of errors).
What is the current behavior?
Currently, the
WKWebView
created byWebViewExt
on iOS will not be destroyed when its Page is removed by backward navigation.One can verify this behavior by loading an HTML file/URL that does something every X second using
setInterval()
. For example play a sound (or maybe just trigger an event that causes Nativescript to log something to the console). When the Page is removed the JS within the WebView keeps running.Also, see my comment in #61.
What is the new behavior?
While I was investigating this issue I found this and this, which led me to try out the changes is this PR which turned out to fix the issue!
Please note that I made my changes directly in the
webview-ext.ios.js
file insidenode_modules/@nota/nativescript-webview-ext
, and I've now copied over the two changed lines (and changingnull
->null!
for TypeScript syntax) for this PR. I'm very new to Nativescript, and to save myself from figuring out exactly whattns plugin install
does (I suspect mostly justnpm install
), I took the liberty to submit this PR without actually testing it since it's a two line fix (I did test it by hot patching the JS file innode_modules
, just not through thetns plugin install
flow).Fixes #61.