You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[webview_flutter_wkwebview] Extended Web View API on iOS to add flexibility when working with local HTML content (#8787)
## Overview
The `readAccessURLProvider` property has been added to the `WebKitWebViewControllerCreationParams` class. This function allows customization of the path to associated resources when loading a local HTML page using `loadFile` on iOS.
### What Is the Issue
Fixesflutter/flutter#136479
The native `WKWebView` takes two arguments when loading local HTML pages:
1. **The file URL** – The local HTML file to be loaded.
2. **The read access URL** – A file or directory that `WKWebView` can access (e.g., .css, .js files).
Currently, the Flutter implementation always sets the parent folder of the specified HTML file as the read access directory. This behavior is not configurable, which limits how local web content can be structured.
For example, the following structure does not work because the .css and .js files are not in the parent directory of the HTML file:
```
/app_resources/
│── styles/
│ ├── main.css
│
│── scripts/
│ ├── app.js
│
│── pages/
├── index.html (Loaded file)
```
With the existing behavior, `WKWebView` cannot `access styles/main.css` and `scripts/app.js` because the parent folder of `index.html` (`/pages/`) does not contain them.
### How This Resolves the Issue
The `readAccessURLProvider` property has been added to the `WebKitWebViewControllerCreationParams` class. This property accepts a function that takes the path of the HTML file being loaded and returns the path to the associated resources.

Each time `loadFile` is called, the controller invokes this function and passes its result as the second argument to the underlying `WKWebView` implementation.
By default, the function returns the parent directory of the specified HTML file, preserving the existing behavior when no custom provider is set.
### Impact on End Users
1. Developers can now explicitly specify the directory that `WKWebView` should allow access to when loading a local HTML page, providing greater flexibility in organizing assets.
2. The existing API signature remains unchanged, ensuring that the update does not require any modifications to existing codebases unless the new functionality is utilized.
0 commit comments