apache / apache/cordova-plugin-inappbrowser

InAppBrowser not load the page with cookies when I use the hardware back button

Open
#992 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.1k
Forks
2.2k
PR merge metrics
No merged PRs in 30d

Description

# Bug Report

I have an application in Ionic 6 and Angular 14 in which I use the InAppBrowser plugin to use a web application of my company and the plugin doesn't load the cache/cookie from web when I use the hardware back button.

## Problem

The plugin works fine in general, the situation is that there is a cookie in the web application that is used for the filters of some lists that are in the web application. When a user filters and enters (for example) a specific client from a list and uses the hardware back button to go back to the list, the filter disappears. From the PC, when you go back the filter is maintained, which means that the cache is maintained.

When I use the DevTools (from Google Chrome: chrome://inspect) to check the Ionic app, the cookie works, but when I don't use it, it doesn't work as I mentioned above. It seems that by doing the hardware back button in the InAppBrowser the cache is not maintained or it is not loaded. All this without changing anything in the code.

So I'm asking if there is a way that when I do the hardware back button it loads the previous page with the cookie/cache loaded. Or if it really shouldn't load anything since the filter has already been applied and the cookie has been overwritten.

### What is expected to happen?

What I expect to happen is that when, for example, a user has used a filter from the web application, when the hardware back button is made, that filter (saved in the cookie) is maintained, just as it does when using the web application. on a PC.

### What does actually happen?

What happens right now is that when using the hardware back button the filter that had been made disappears, but the thing is that the cookie still exists, since using the DevTools it works without having made any changes to the code.

## Information

### Command or Code

This is how I create the InAppBrowser:
```
browser = this.iab.create(pageContentUrl, '_blank', 'location=no,zoom=no,fullscreen=no,clearcache=no,clearsessioncache=no,hidden=yes,toolbar=no');
```

I have this to check the cookie:
```
browser.on('loadstart').subscribe((e: InAppBrowserEvent) => {
browser.executeScript({
code: "(function() { \
console.log(document.cookie);\
})();"
});
});
```
### Update

I've test this under onCreate in MainActivity (Android Studio) and it doesn't fix the issue:
```
public class MainActivity extends BridgeActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);

if(webView.canGoBack()){
webView.goBack();
}
}
}
```

### Environment, Platform, Device

- Android 11 - Samsung Galaxy A12

### Version information
Ionic info:

```
Ionic:
- Ionic CLI : 6.20.1 (C:\Users\david\AppData\Roaming\npm\node_modules\@ionic\cli)
- Ionic Framework : @ionic/angular 6.2.5
- @angular-devkit/build-angular : 14.2.1
- @angular-devkit/schematics : 14.2.1
- @angular/cli : 14.2.1
- @ionic/angular-toolkit : 6.1.0

Capacitor:
- Capacitor CLI : 4.1.0
- @capacitor/android : 4.1.0
- @capacitor/core : 4.1.0
- @capacitor/ios : 4.1.0

Utility:
- cordova-res : 0.15.4
- native-run : 1.6.0

System:
- NodeJS : v16.15.1 (C:\Program Files\nodejs\node.exe)
- npm : 8.11.0
- OS : Windows 10
```

List of plugins installed and dependencies from package.json :
```
"@angular/common": "^14.0.0",
"@angular/core": "^14.0.0",
"@angular/forms": "^14.0.0",
"@angular/platform-browser": "^14.0.0",
"@angular/platform-browser-dynamic": "^14.0.0",
"@angular/router": "^14.0.0",
"@awesome-cordova-plugins/device": "^5.44.0",
"@awesome-cordova-plugins/http": "^5.44.0",
"@awesome-cordova-plugins/in-app-browser": "^6.3.0",
"@awesome-cordova-plugins/network": "^5.45.0",
"@awesome-cordova-plugins/screen-orientation": "^5.45.0",
"@capacitor/android": "4.1.0",
"@capacitor/app": "4.0.1",
"@capacitor/core": "4.1.0",
"@capacitor/device": "^4.1.0",
"@capacitor/haptics": "4.0.1",
"@capacitor/ios": "4.1.0",
"@capacitor/keyboard": "4.0.1",
"@capacitor/local-notifications": "^4.1.0",
"@capacitor/push-notifications": "^4.1.0",
"@capacitor/status-bar": "4.0.1",
"@capacitor/toast": "^4.1.0",
"@ionic/angular": "^6.1.9",
"@ionic/storage-angular": "^3.0.6",
"cordova-plugin-advanced-http": "^3.3.1",
"cordova-plugin-device": "^2.1.0",
"cordova-plugin-file": "^7.0.0",
"cordova-plugin-inappbrowser": "^5.0.0",
"cordova-plugin-lottie-splashscreen": "github:timbru31/cordova-plugin-lottie-splashscreen",
"cordova-plugin-network-information": "^3.0.0",
"cordova-plugin-screen-orientation": "^3.0.2",
"ionicons": "^6.0.3",
"rxjs": "~6.6.0",
"tslib": "^2.2.0",
"zone.js": "~0.11.4"
```

## Checklist

- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above

Contributor guide

Open the contributing guide

Research direction

Start with the Android MainActivity setup and the InAppBrowser loadstart handler shown in the report, then reproduce the hardware-back behavior on Android 11 using the provided browser options. Done means the filtered list retains its cookie-backed state after hardware back without requiring DevTools; the report does not identify a plugin source file or test to run.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, angular, java, typescript
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.