Notalib / nativescript-webview-ext

Nativescript plugin with extended WebView functionality
Apache License 2.0
76 stars 37 forks source link

Isn't destroying #61

Closed jibon57 closed 4 years ago

jibon57 commented 4 years ago

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

I was trying to play audio file from a website which was using HTML5 audio tag. When I navigated to another page of my APP audio was keep playing. How can I destroy it properly?

Thanks

jibon57 commented 4 years ago

At present I am reloading the view on navigatingFromEvent like this:

let t = this;
this.page.on(Page.navigatingFromEvent, function (data) {
    t.page.off(Page.navigatingFromEvent);
    t.webViewExt.reload();
})

I think there should be some other good way..

m-abs commented 4 years ago

Views/Page are not destroyed in NativeScript when you forward navigate to another page, I guess that's why it keeps playing.

You might be able to solve it like this (not tested):

this.page.on(Page.navigatingFromEvent, function (data) {
  if (this.webViewExt) {
    this.webViewExt.executeJavascript(`var els = document.querySelectorAll(\"video\"); for (var i = els.length - 1; i >= 0; i--) { els[i].pause(); };`);
  }
}, this)
jibon57 commented 4 years ago

@m-abs thank you. Is there any other way to destroy the page? Or webViewExt view?

m-abs commented 4 years ago

@jibon57

It's beyond the scope of this plugin, but you could try to set visibility=colapsed on navigating from and reset it to visibility=visible, that should destroy the native webview, but also the current state and history.

heyman commented 3 years ago

I'm having the same issue. I have a <Page> with a <WebViewExt> component (nativescript-vue) where I load an HTML file that plays a sound every fifth second (using setInterval within the loaded HTML file). When I leave the page by backward navigating, using $navigateBack, the sound keeps playing every fifth second. If i navigate forward to the Page again, and then back, the sound now plays twice every fifth seconds.

When I add a console.log() to the beforeDestroy hook of my Page component, I can see that it gets called. For some reason the WebViewExt instance is kept alive somewhere.

EDIT: This is on iOS btw.

m-abs commented 3 years ago

Thanks to @heyman I've published v7.0.2 with a fix for this problem. Thank you for identifying the cause and providing a fix.