Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beforeload event fires only on odd links #686

Open
3 tasks done
koekaverna opened this issue Apr 29, 2020 · 2 comments · May be fixed by #755
Open
3 tasks done

beforeload event fires only on odd links #686

koekaverna opened this issue Apr 29, 2020 · 2 comments · May be fixed by #755

Comments

@koekaverna
Copy link

koekaverna commented Apr 29, 2020

Bug Report

Problem

the 'beforeload' odd fires only on even links, on even links it doesn’t work

What is expected to happen?

It should fire always

What does actually happen?

It fire only odd (half times)

Information

Repository to reproduce
https://github.com/koekaverna/cordova-inapp-testing

Command or Code

Tested with chome DevTools: chrome://inspect/#devices console output
and android emulator

Environment, Platform, Device

Pixel_2_API_R:5584

Version information

Cordova: 9.0.0 (cordova-lib@9.0.1)

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@koekaverna koekaverna changed the title beforeload event fires only on even links beforeload event fires only on odd links Apr 30, 2020
dpa99c added a commit to dpa99c/cordova-plugin-inappbrowser-popup-bridge that referenced this issue Jul 7, 2020
@dpa99c
Copy link
Contributor

dpa99c commented Jul 7, 2020

I am able to repro this: the beforeload event is only being fired intermittently because the native shouldOverrideUrlLoading method is being called intermittently.

I've found a solution which seems to work in this SO answer - adding this seems to resolve the issue and beforeload is fired on every request as would be expected on Android:

inAppWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

While MIXED_CONTENT_ALWAYS_ALLOW is not recommended, setting MIXED_CONTENT_COMPATIBILITY_MODE or MIXED_CONTENT_NEVER_ALLOW seems to cause the intermittent failure to invoke shouldOverrideUrlLoading, so I would propose setting MIXED_CONTENT_ALWAYS_ALLOW to resolve this issue.

@PDLMobileApps
Copy link
Contributor

I am able to repro this: the beforeload event is only being fired intermittently because the native shouldOverrideUrlLoading method is being called intermittently.

I've found a solution which seems to work in this SO answer - adding this seems to resolve the issue and beforeload is fired on every request as would be expected on Android:

inAppWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

While MIXED_CONTENT_ALWAYS_ALLOW is not recommended, setting MIXED_CONTENT_COMPATIBILITY_MODE or MIXED_CONTENT_NEVER_ALLOW seems to cause the intermittent failure to invoke shouldOverrideUrlLoading, so I would propose setting MIXED_CONTENT_ALWAYS_ALLOW to resolve this issue.

We looked into that and it did not solve the issue. However, PR#755 does solve it. The code that is modified in that PR seems to be quite old/obsolete and causes the issue reported in this bug. Could any reviewer consider reviewing it? Thanks!

leonardo-fernandes added a commit to leonardo-fernandes/cordova-plugin-inappbrowser that referenced this issue Dec 13, 2021
… in apache#686


The waitForBeforeload flag was preventing beforeLoad from being called on every GET request.
alexgerardojacinto added a commit to OutSystems/cordova-plugin-inappbrowser that referenced this issue Aug 30, 2023
…ty (#42)

* Fix memory leak - initially reported in apache#290

Whenever closing an InAppBrowser instance, a webview was left in memory with about:blank page.
This change fixes the issue by destroying and freeing the inAppWebView object.

* Fix beforeLoad not being called in some requests - initially reported in apache#686

The waitForBeforeload flag was preventing beforeLoad from being called on every GET request.

* Do not lose callbackContext when opening a SYSTEM url

This fixes a condition where it was not possible to open a SYSTEM url while an InAppBrowser instance is displayed. The callbackContext of the InAppBrowser instance was lost when the SYSTEM url was opened. This fixes the issue by not setting the callbackContext on SYSTEM urls.

* Fix crash when pausing/resuming application after closing InAppBrowser

* Fix _loadAfterBeforeload callback not working due to this.rootName not being defined.

* Reset beforeload variable if a new instance of InAppBrowser is opened without beforeload setting

* chore: update changelog

References: https://outsystemsrd.atlassian.net/browse/RMET-2802

* refactor: remove empty lines

* refactor: use ternary operator and remove unnecessary ones

Why: We can refactor the if-else block that assigns a value to beforeload to use a ternary operator. On the other hand, we can remove the unnecessary ternary operators used to assign a boolean value. They are redundant.

References: https://outsystemsrd.atlassian.net/browse/RMET-2802

---------

Co-authored-by: Leonardo Monteiro Fernandes <leonardo.monteiro.fernandes@gmail.com>
Co-authored-by: Nelson Lopes Silva <5671236+nflsilva@users.noreply.github.com>
alexgerardojacinto added a commit to OutSystems/cordova-plugin-inappbrowser that referenced this issue Aug 31, 2023
* RMET-2119 InAppBrowser Plugin - Check for element before obtaining it (#40)

* fix: check if there's a next token before trying to obtain it

References: https://outsystemsrd.atlassian.net/browse/RMET-2119

* chore: update changelog

* RMET-2802 InAppBrowser Plugin - Multiple minor fixes from the community (#42)

* Fix memory leak - initially reported in apache#290

Whenever closing an InAppBrowser instance, a webview was left in memory with about:blank page.
This change fixes the issue by destroying and freeing the inAppWebView object.

* Fix beforeLoad not being called in some requests - initially reported in apache#686

The waitForBeforeload flag was preventing beforeLoad from being called on every GET request.

* Do not lose callbackContext when opening a SYSTEM url

This fixes a condition where it was not possible to open a SYSTEM url while an InAppBrowser instance is displayed. The callbackContext of the InAppBrowser instance was lost when the SYSTEM url was opened. This fixes the issue by not setting the callbackContext on SYSTEM urls.

* Fix crash when pausing/resuming application after closing InAppBrowser

* Fix _loadAfterBeforeload callback not working due to this.rootName not being defined.

* Reset beforeload variable if a new instance of InAppBrowser is opened without beforeload setting

* chore: update changelog

References: https://outsystemsrd.atlassian.net/browse/RMET-2802

* refactor: remove empty lines

* refactor: use ternary operator and remove unnecessary ones

Why: We can refactor the if-else block that assigns a value to beforeload to use a ternary operator. On the other hand, we can remove the unnecessary ternary operators used to assign a boolean value. They are redundant.

References: https://outsystemsrd.atlassian.net/browse/RMET-2802

---------

Co-authored-by: Leonardo Monteiro Fernandes <leonardo.monteiro.fernandes@gmail.com>
Co-authored-by: Nelson Lopes Silva <5671236+nflsilva@users.noreply.github.com>

---------

Co-authored-by: Leonardo Monteiro Fernandes <leonardo.monteiro.fernandes@gmail.com>
Co-authored-by: Nelson Lopes Silva <5671236+nflsilva@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment