Skip to content

[webview_flutter_web] Add WebWebViewController.runJavaScript#10215

Closed
sophiebremer wants to merge 8 commits intoflutter:mainfrom
sophiebremer:web_web_view_run_java_script
Closed

[webview_flutter_web] Add WebWebViewController.runJavaScript#10215
sophiebremer wants to merge 8 commits intoflutter:mainfrom
sophiebremer:web_web_view_run_java_script

Conversation

@sophiebremer
Copy link

@sophiebremer sophiebremer commented Oct 11, 2025

This PR (replaces #9835) adds an implementation for WebWebViewController.runJavaScript and changes the way WebWebViewController.loadHtmlString injects HTML code while also adding support for the baseUrl option.

The following issues are fixed:

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

@sophiebremer
Copy link
Author

Hello @mdebbar!

Please provide guidance. Not all tests are successful, and how to add a useful test for WebWebViewController.runJavaScript without browser context is unclear to me.

@sophiebremer sophiebremer marked this pull request as ready for review October 21, 2025 07:15
@sophiebremer sophiebremer requested a review from mdebbar as a code owner October 21, 2025 07:15
@stuartmorgan-g stuartmorgan-g added the triage-web Should be looked at in web triage label Nov 4, 2025
'load',
() {
try {
_webWebViewParams.iFrame.contentDocument?.write(html.toJS);
Copy link
Collaborator

Choose a reason for hiding this comment

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

team-web will still need to do a full review, but in the meantime: won't this change to loadHtmlString silently break any case where baseUrl is passed, as a regression from the previous behavior?

Copy link
Author

Choose a reason for hiding this comment

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

This is valid concern. I see two different options to address it:

  1. The previous implementation gets added as a fallback in the catch block.

  2. We introduce a new controller parameter option to activate this PRs implementation and use the existing implementation by default as before.

What are your suggestions / thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@mdebbar How do you want to handle branching for different origin setups?

2. We introduce a new controller parameter option to activate this PRs implementation and use the existing implementation by default as before.

Would the parameter add any information we don't already have? Can't we determine at runtime if the origins match?

@sophiebremer
Copy link
Author

Hello! We realised that we need more CORS flexibility which is in conflict with backward compatibility. Therefore we decided to go with a custom implementation based on the webview interfaces to support our usage goals. Thank you for taking the time and considering the feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: webview_flutter platform-web triage-web Should be looked at in web triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants