Description
Bug Report
Problem
What is expected to happen?
When I am using a beforeload event listener, passing a url to the callback should load that URL as expected.
What does actually happen?
cordova-plugin-inapp browser fails to load the url and instead throws an error:
(URL blacked out)
Information
What is significant here is that this request is a 302 redirect. I believe that this may be the catalyst for why this error is popping up but I am not sure if inapp-browser's event listener just straight up can't handle "redirect" urls, or if I am doing something wrong.
Here is some info on the requested URL when it is made successfully (without the beforeload handler and without the error being thrown, notice how it is has a status of "302 Found"). How this works is that the "Request URL" is the original URL being requested, and the "Location" response header is the new URL that the client should be redirected too:
Command or Code
let inAppBrowserRef = window.open(url, '_blank', 'location=no,hidden=yes,toolbar=yes,enableViewportScale=yes,shouldPauseOnSuspend=yes,allowInlineMediaPlayback=yes,usewkwebview=yes');
inAppBrowserRef.hidden = true;
inAppBrowserRef.addEventListener('beforeload', (params, callback) => {
if(params.url.match(".pdf")){
console.log('MATCH PDF');
window.open(params.url, '_system');
} else {
console.log('DEFAULT HANDLING');
// THIS IS WHERE THE ERROR OCCURS
callback(params.url);
}
});
...
inAppBrowserRef.addEventListener('loaderror', (event) => {
const msg = `[${event.code}] Cannot open URL: [${event.url}]. Message from the server is: ${event.message}`;
inAppBrowserRef.close();
inAppBrowserRef = undefined;
handleLoadError(dispatch, msg);
});
Environment, Platform, Device
- MacBook Pro Sonoma 14.4.1
- Xcode 15.3 iPhone 15 Pro Simulator
Version information
Cordova: Cordova 11, cordova-ios@6, cordova-plugin-inappbrowser v6
Checklist
- I searched for existing GitHub issues
- I updated all Cordova tooling to most recent version (not possible due to quirks with Node and other unmaintained plugins)
- I included all the necessary information above