injectJavascriptFileFromUrl method

Future<void> injectJavascriptFileFromUrl({
  1. required WebUri urlFile,
  2. ScriptHtmlTagAttributes? scriptHtmlTagAttributes,
})

Injects an external JavaScript file into the WebView from a defined url.

scriptHtmlTagAttributes represents the possible the <script> HTML attributes to be set.

NOTE: This method shouldn't be called in the PlatformWebViewCreationParams.onWebViewCreated or PlatformWebViewCreationParams.onLoadStart events, because, in these events, the WebView is not ready to handle it yet. Instead, you should call this method, for example, inside the PlatformWebViewCreationParams.onLoadStop event or in any other events where you know the page is ready "enough".

Officially Supported Platforms/Implementations:

  • Android WebView
  • iOS WKWebView
  • Linux WPE WebKit:
    • This method is implemented using JavaScript.
  • macOS WKWebView
  • Web <iframe> but requires same origin

Parameters - Officially Supported Platforms/Implementations:

  • urlFile: all platforms
  • scriptHtmlTagAttributes: all platforms

Use the PlatformInAppWebViewController.isMethodSupported method to check if this method is supported at runtime.

Implementation

Future<void> injectJavascriptFileFromUrl({
  required WebUri urlFile,
  ScriptHtmlTagAttributes? scriptHtmlTagAttributes,
}) => platform.injectJavascriptFileFromUrl(
  urlFile: urlFile,
  scriptHtmlTagAttributes: scriptHtmlTagAttributes,
);