You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2021/09/22 18:03:37 UTC

[GitHub] [cordova] Qualphey opened a new issue #303: Control of the WebView from an independent javascript instance.

Qualphey opened a new issue #303:
URL: https://github.com/apache/cordova/issues/303


   # Feature Request
   
   ## Motivation Behind Feature
   <!-- Why should this feature be implemented? What problem does it solve? -->
   This feature would enable:
   - Modifying html before loading it (i.e. rendering it with some templating engine).
   - Smooth development using multi-page app architecture.
   
   ## Feature Description
   <!-- 
   Describe your feature request in detail
   Please provide any code examples or screenshots of what this feature would look like
   Are there any drawbacks? Will this break anything for existing users? 
   -->
   An option to run Cordova apps with a "background" javascript instance that could control and communicate with the WebView.
   
   ## Alternatives or Workarounds
   <!-- 
   Describe alternatives or workarounds you are currently using 
   Are there ways to do this with existing functionality?
   -->
   As an alternative you can use a single html file containing an iframe and scripts. Instead of loading desired pages in WebView the app would read the html file, render it adding mutation observers, write contents to a different file and then load that file in an iframe.
   
   Drawbacks of the workaround:
   - Apps become harder to debug.
   - Unnecessary file reads/writes.
   - Mutation observers have to be rendered into html in order to override link behavior. So that the iframe would send a message back to WebView making it read the next html file, render, write and load it in the iframe.
   - On android platform `applicationDirectory` is read only, so you have to write the rendered html file to a different directory. In this case you have to either: copy all resources that are loaded using relative paths into the same directory or modify relative path when rendering html.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[GitHub] [cordova] breautek commented on issue #303: Control of the WebView from an independent javascript instance.

Posted by GitBox <gi...@apache.org>.
breautek commented on issue #303:
URL: https://github.com/apache/cordova/issues/303#issuecomment-925352497


   Looks like I stand corrected.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[GitHub] [cordova] breautek edited a comment on issue #303: Control of the WebView from an independent javascript instance.

Posted by GitBox <gi...@apache.org>.
breautek edited a comment on issue #303:
URL: https://github.com/apache/cordova/issues/303#issuecomment-925336317


   > Modifying html before loading it (i.e. rendering it with some templating engine).
   
   ~I don't think this is feasible. The native APIs expects an actual file URL of some sort, you can't just simply pass through HTML data for it to load. So this in itself, won't solve some of the mentioned workaround drawbacks.~ (https://github.com/apache/cordova/issues/303#issuecomment-925350129)
   
   > Smooth development using multi-page app architecture.
   
   Multi-page architecture is really not recommended in Cordova environments. If you have multiple pages, you constantly have to unload/re-initialise Cordova plugins, in addition to any of your app assets. Single-Page Apps is far more efficient, even in a general sense. I'd recommend taking a read over our [Best Practices](https://cordova.apache.org/docs/en/10.x/guide/next/index.html#best-practices-for-cordova-apps).
   
   > On android platform applicationDirectory is read only, so you have to write the rendered html file to a different directory. In this case you have to either: copy all resources that are loaded using relative paths into the same directory or modify relative path when rendering html.
   
   On some other platforms, namely iOS, the WKWebView will refuse to load anything outside of the iOS equivalent of `applicationDirectory`. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[GitHub] [cordova] Qualphey commented on issue #303: Control of the WebView from an independent javascript instance.

Posted by GitBox <gi...@apache.org>.
Qualphey commented on issue #303:
URL: https://github.com/apache/cordova/issues/303#issuecomment-925689537


   > If you have multiple pages, you constantly have to unload/re-initialise Cordova plugins, in addition to any of your app assets.
   
   Yeah, but in some cases I think it might be saving up some memory i.e. if different pages use different plugins and assets. Multi-page architecture would be very useful for big projects.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[GitHub] [cordova] Qualphey edited a comment on issue #303: Control of the WebView from an independent javascript instance.

Posted by GitBox <gi...@apache.org>.
Qualphey edited a comment on issue #303:
URL: https://github.com/apache/cordova/issues/303#issuecomment-925350129


   > I don't think this is feasible. The native APIs expects an actual file URL of some sort, you can't just simply pass through HTML data for it to load.
   
   Are you sure about that? What exact native APIs are you talking about?
   I've found these methods for [UIWebView](https://developer.apple.com/documentation/uikit/uiwebview/1617979-loadhtmlstring), [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview/1415004-loadhtmlstring) and [Android WebView](https://developer.android.com/reference/android/webkit/WebView#loadDataWithBaseURL(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String)). With them you can load an HTML string into WebView and also set the base url for relative paths.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[GitHub] [cordova] breautek commented on issue #303: Control of the WebView from an independent javascript instance.

Posted by GitBox <gi...@apache.org>.
breautek commented on issue #303:
URL: https://github.com/apache/cordova/issues/303#issuecomment-925336317


   > Modifying html before loading it (i.e. rendering it with some templating engine).
   
   I don't think this is feasible. The native APIs expects an actual file URL of some sort, you can't just simply pass through HTML data for it to load. So this in itself, won't solve some of the mentioned workaround drawbacks.
   
   > Smooth development using multi-page app architecture.
   
   Multi-page architecture is really not recommended in Cordova environments. If you have multiple pages, you constantly have to unload/re-initialise Cordova plugins, in addition to any of your app assets. Single-Page Apps is far more efficient, even in a general sense. I'd recommend taking a read over our [Best Practices](https://cordova.apache.org/docs/en/10.x/guide/next/index.html#best-practices-for-cordova-apps).
   
   > On android platform applicationDirectory is read only, so you have to write the rendered html file to a different directory. In this case you have to either: copy all resources that are loaded using relative paths into the same directory or modify relative path when rendering html.
   
   On some other platforms, namely iOS, the WKWebView will refuse to load anything outside of the iOS equivalent of `applicationDirectory`. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[GitHub] [cordova] Qualphey commented on issue #303: Control of the WebView from an independent javascript instance.

Posted by GitBox <gi...@apache.org>.
Qualphey commented on issue #303:
URL: https://github.com/apache/cordova/issues/303#issuecomment-925350129


   > I don't think this is feasible. The native APIs expects an actual file URL of some sort, you can't just simply pass through HTML data for it to load.
   Are you sure about that? What exact native APIs are you talking about?
   I've found these methods for [UIWebView](https://developer.apple.com/documentation/uikit/uiwebview/1617979-loadhtmlstring), [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview/1415004-loadhtmlstring) and [Android WebView](https://developer.android.com/reference/android/webkit/WebView#loadDataWithBaseURL(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String)). With them you can load an HTML string into WebView and also set the base url for relative paths.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[GitHub] [cordova] breautek edited a comment on issue #303: Control of the WebView from an independent javascript instance.

Posted by GitBox <gi...@apache.org>.
breautek edited a comment on issue #303:
URL: https://github.com/apache/cordova/issues/303#issuecomment-925336317


   > Modifying html before loading it (i.e. rendering it with some templating engine).
   
   ~I don't think this is feasible. The native APIs expects an actual file URL of some sort, you can't just simply pass through HTML data for it to load. So this in itself, won't solve some of the mentioned workaround drawbacks.~
   
   > Smooth development using multi-page app architecture.
   
   Multi-page architecture is really not recommended in Cordova environments. If you have multiple pages, you constantly have to unload/re-initialise Cordova plugins, in addition to any of your app assets. Single-Page Apps is far more efficient, even in a general sense. I'd recommend taking a read over our [Best Practices](https://cordova.apache.org/docs/en/10.x/guide/next/index.html#best-practices-for-cordova-apps).
   
   > On android platform applicationDirectory is read only, so you have to write the rendered html file to a different directory. In this case you have to either: copy all resources that are loaded using relative paths into the same directory or modify relative path when rendering html.
   
   On some other platforms, namely iOS, the WKWebView will refuse to load anything outside of the iOS equivalent of `applicationDirectory`. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[GitHub] [cordova] mysorian commented on issue #303: Control of the WebView from an independent javascript instance.

Posted by GitBox <gi...@apache.org>.
mysorian commented on issue #303:
URL: https://github.com/apache/cordova/issues/303#issuecomment-955801464


   > > I don't think this is feasible. The native APIs expects an actual file URL of some sort, you can't just simply pass through HTML data for it to load.
   > 
   > Are you sure about that? What exact native APIs are you talking about? I've found these methods for [UIWebView](https://developer.apple.com/documentation/uikit/uiwebview/1617979-loadhtmlstring), [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview/1415004-loadhtmlstring) and [Android WebView](https://developer.android.com/reference/android/webkit/WebView#loadDataWithBaseURL(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String)). With them you can load an HTML string into WebView and also set the base url for relative paths.
   
   I could load HTML string to Android WebView. I have tried a Base64 of an image as well to embed in Web View.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org