Files
MichaelDimmitt 3c82896d8f Fix image in all sample readmes (#529)
* fix images in readme

* fix all sample readmes by pointing all images to correct apps location
2021-02-25 09:49:17 +11:00
..
2020-12-04 09:18:01 +11:00
2020-12-04 09:18:01 +11:00
2020-12-04 09:18:01 +11:00
2020-12-04 09:18:01 +11:00
2020-12-04 09:18:01 +11:00
2020-12-04 09:18:01 +11:00
2020-12-04 09:18:01 +11:00
2020-12-04 09:18:01 +11:00
2020-12-04 09:18:01 +11:00
2020-12-04 09:18:01 +11:00
2020-12-04 09:18:01 +11:00

Try it now in CWS

Accessing the main world with <webview>.executeScript()

Web view content scripts run in an isolated world. This means that they can access the current page's DOM, but cannot share objects with scripts included in the DOM because scripts in the DOM run in the main world. For a more detailed explanation, checkout this video.

Running in an isolated world is usually what the developer wants because access to the DOM is enough. Sometimes, the developer may want to access Javascript objects in the main world. This sample shows good and bad examples of injecting Javascript into a <webview> that is intended to run in the main world. To do this correctly, content script must create a <script> tag and inject it into the DOM. Then, the script contained within the <script> tag will be run in the main world.

The sample shows a page that contains an animated dragon. The injected script adds the ability to construct dragons that animate in sync. In order to do so, the script needs access to the Dragon FOAM model. To gain access, the injected script inserts a <script> tag into the DOM.

The sample contains two app windows: Incorrect injection attempts to inject the script directly and Correct injection injects the script into a <script> tag in the DOM.

Resources

Screenshot

screenshot