The documentation for <webview> is unclear on when executeScript can be called and how it relates to navigation.
https://developer.chrome.com/apps/tags/webview#method-executeScript
Context: We wish to inject a polyfill into a <webview> before any document-provided script executes.
jrw@ reports that calling it before webview.load fires results in an error. Calling it in webview.load may work - is the Document created yet? Calling it in webview.contentload may be too late for us (has document script execution begun yet)?
As a workaround jrw@ is using a content script injected on document_start and MutationObserver to insert a <script> immediately after <head> is created. This is an ugly hack that could be avoided with executeScript.
In short, the behavior of webview.executeScript needs to be documented:
1. Before load.
2. In the load handler.
3. After load fires and before contentload does.
4. In the contentload handler.
5. After contentload fires.
And content script injection points (document_start, document_idle, document_end) need to also be included in that sequence.
Comment 1 by fsam...@chromium.org
, Feb 23 2017