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

refactor webview with new package to support header override #1731

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

TheNoumanDev
Copy link
Member

replaced 'https://pub.dev/packages/webview_flutter' with 'https://pub.dev/packages/flutter_inappwebview' to support headers override.
Added following new properties:

  WebView:
    styles:
      height: ${device.height - device.safeAreaBottom - device.safeAreaTop - 10 }
    headers:
      "X-SECRET": "057cae9af7bda467269736e222bbf241e31f1c8d"
    headerOverrideRules:
      - urlPattern: 'api.acc.kpn.com'
        matchType: CONTAINS  # CONTAINS, EXACT, REGEX
        headers:
          X-SECRET: 057cae9af7bda467269736e222bbf241e31f1c8d
        mergeExisting: true

Test with following android and web, things worked fine by my end, iOS still needs some testing.

  • Kitchen sink Example worked fine (Android, web)
  • Kpn login (the top error is coming, bcz sometimes It have options API calls which don't have header but login works as it has that error):
kpnwebview.mp4
  • Trip App worked fine on android with cookies being passed, but on web I wasn't able to login , it was given error
webview.mp4

Copy link
Collaborator

@kmahmood74 kmahmood74 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty big change, let's have a zoom call to go over it

List<HeaderOverrideRule> parseHeaderRules(YamlList yamlList) {
return yamlList.map((rule) {
Map<String, String> headers = {};
(rule['headers'] as YamlMap).forEach((key, value) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by assuming it's a YamlMap, we make it impossible for someone to set this value in js. Please just use Map

@@ -17,6 +17,7 @@ import 'package:flutter/material.dart';
class WebViewState extends EWidgetState<EnsembleWebView> {
final IFrameElement _iframeElement = IFrameElement();
HtmlElementView? htmlView;
final String viewId = 'iframeElement-${DateTime.now().millisecondsSinceEpoch}';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why make it a unique viewId, is it causing memory leaks?

(int viewId) => _iframeElement,
);

return HtmlElementView(
key: UniqueKey(),
viewType: 'iframeElement',
viewType: viewId,
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add a dispose method here and dispose off the htmlView and iframeElement. That should get rid of the memory leak


// Set cookie for main domain
await widget.controller.cookieManager.setCookie(
url: Uri.parse('https://$cookieDomain'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't assume that it's always https. Please get the protocol from the url as well and don't hardcode it

final cookieDomain = cookieData['domain'] ?? mainUrl.host;

await widget.controller.cookieManager.setCookie(
url: Uri.parse('https://$cookieDomain'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants