Comments (7)
Still not managing to get this working. There is no mention of it in the types.d.ts file which I think is why it's triggering the error.
If I use // @ts-ignore it bypasses the error but then I get a javascript error in the console when running in the simulator.
I'm wondering if the beforeload callback is working in the current version? Many thanks.
from cordova-plugin-inappbrowser.
Assuming you're using typescript, I would suppose it to be something like:
browser.
on("beforeload").
subscribe( (ev: InAppBrowserEvent, callback: (url: string) => void ) => {
console.log(ev.url);
callback(ev.url);
}, err => { });
For people using typescript, I guess it would be useful to annonate the type for this callback.
from cordova-plugin-inappbrowser.
Feedback of @brodybits on this was:
The idea of passing an asynchronous callback to an event listener seems really strange to me. While I can definitely understand the logic behind making it asynchronous between native and JavaScript I don't think this really justifies introducing what looks like new paradigm in event listeners. I can think of the following alternative approaches:
- event listener synchronously returns non-null value to indicate that application does not want to load the URL, in a similar fashion to a standard beforeload event handler ref: [1] (preferred)
- event listener throws an exception to override default behavior, in a similar fashion to backbutton event on Windows ref: [2]
- new asynchronous callback mechanism outside the event handler mechanism that the application can use to filter URL load requests
The code also seems to assume that there would never be multiple outstanding load requests, which I would not agree with. What if a user clicks on a couple links in succession, or the webpage JavaScript issues multiple HTTP(S) requests?
[1] https://eloquentjavascript.net/15_event.html#p_nu8/BUQa7r
[2] https://cordova.apache.org/docs/en/latest/cordova/events/events.html#windows-quirks
A synchronous callback would be preferable, but that needs to be technically possible in Android's and iOS's WebView implementation, because the callback may take some time (because it involves a Javascript invocation).
And then, regarding beforeload
, @wvengen mentioned:
Reading up on HTML's
beforeunload
event, I do seepreventDefault()
, e.g. on MDN, W3C HTML 5.0 (suggestinge.returnValue
) and WHATWG (preferringe.preventDefault()
).I would suggest to adopt
e.returnValue
ande.preventDefault()
in InAppBrowser's newbeforeunload
event. This is in-line with current standards, allows using the existing event handling infrastructure, and by updating the event this will also work with multiple event handlers. It does require some changes to the event object passed on to the handlers (so that returnValue can be reported back, ande.preventDefault()
is available).
from cordova-plugin-inappbrowser.
I'm struggling to see how to use this with Ionic 4. How does one call the callback function in the beforeload event handler when using the new .subscribe style way of dealing with events?
browser.on("beforeload") .subscribe( (ev: InAppBrowserEvent) => {
console.log(ev.url);
browser._loadAfterBeforeload(ev.url);
}, err => { });
The event is being fired as I see the url in the console - but the above wont build - I just guessed with the _loadAfterBeforeload function but it doesn't work.
How do I call the callback to continue loading the url in this event?
from cordova-plugin-inappbrowser.
In the example's beforeLoadCallback
you can see that a second parameter to the callback is a function you can call to load the url.
from cordova-plugin-inappbrowser.
Thanks - but where do I reference this second parameter in the above code?
from cordova-plugin-inappbrowser.
Thanks so much for this, I think we're close! - unfortunately I see this error now:
Argument of type '(ev: InAppBrowserEvent, callback: (url: string) => void) => void' is not assignable to parameter of type '(value: InAppBrowserEvent) => void'.
Any ideas?
from cordova-plugin-inappbrowser.
Related Issues (20)
- Android FR: Enable zoom without displaying on-screen zoom controls
- Calling window.print() does not work
- Keychain not work with inappbrowser HOT 1
- Disable close button (Done) for iOS
- InAppBrowser does not open Youtube Links Properly HOT 12
- The preference name "MediaPlaybackRequiresUserAction" has been deprecated. It is recommended to replace this preference with "MediaTypesRequiringUserActionForPlayback."
- When can we expect latest 6.0.0 version release on npm? HOT 1
- The www/inappbrowser.css file should be removed because it was only for the Windows platform HOT 1
- Cannot build iOS Ionic Capacitor project HOT 5
- 6.0.0 Update throws error while archiving iOS project: "'Cordova/CDVWebViewProcessPoolFactory.h' file not found" HOT 1
- "browser.on('loaderror')" does not work properly on iOS.
- executeScript not working in colab HOT 4
- How to build this plugin for node_modules? HOT 2
- Add option to respect/ignore safe area on iOS
- ref.executeScript can't write clipboard HOT 5
- window.open doesnt work inside the opened webview HOT 2
- Warning when submitting to play store - JavaScript Interface Injection HOT 3
- @awesome-cordova-plugins/in-app-browser, this plugin is not sending the device id to azure while login + iOS HOT 3
- Angular 15 webpage not loading correctly in inappbrowser (Android < 11) HOT 1
- Hide Location & toolbar on scroll
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cordova-plugin-inappbrowser.