Skip to content
This repository has been archived by the owner on Mar 14, 2023. It is now read-only.

Embedded js content not working with URL source type #37

Closed
sdabet-orpheo opened this issue Sep 22, 2021 · 3 comments
Closed

Embedded js content not working with URL source type #37

sdabet-orpheo opened this issue Sep 22, 2021 · 3 comments

Comments

@sdabet-orpheo
Copy link

sdabet-orpheo commented Sep 22, 2021

It seems that embedded js content only works with HTML source type, but not URL source type (at least on web platform, didn't test on Android/iOS).

Test with HTML source type (on web platform):

WebViewX(
        width: 500,
        height: 500,
        initialContent: "<h1>Hello</h1>",
        initialSourceType: SourceType.html,
        jsContent: {EmbeddedJsContent(js: "console.log('hello');")},
)

=> I can see the "hello" message in the browser's console.

Test with URL source type (on web platform):

WebViewX(
        width: 500,
        height: 500,
        initialContent: "https://httpbin.org/get",
        initialSourceType: SourceType.url,
        jsContent: {EmbeddedJsContent(js: "console.log('hello');")},
)

=> no message in console

@adrianflutur
Copy link
Owner

Hi, you're right, it doesn't work for SourceType.url. This is documented here #27 , specifically:

Calling any method that will interact with the page's source (i.e. call JS methods, callbacks, execute JS etc) from the controller only work when using SourceType.urlBypass or SourceType.html. This is because only in theese 2 situations the package can actually inject that JS code inside the page source. When using SourceType.url, iframe's content does not actually belong to us - it is loaded from a different domain so we're not allowed to do that.

@adrianflutur
Copy link
Owner

Closing this for now, please open another issue if you still need help or encounter an issue.

@bettysteger
Copy link

Sorry, but i gotta ask, why this doesn't work. I have used a pwa-wrapper code for iOS in swift, and there i can add javascript to the webview, see line 99 here: https://github.com/bettysteger/iOS-PWA-Wrapper/blob/master/ios-pwa-wrapper/ViewController.swift#L99

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants