-
-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve script injection for native bridge #87
Conversation
Review notes:
Some suggestions on other ways this issue could be fixed:
I think the apploader.js approach might be one of the best solutions but we need to make sure the web team doesn't change it without warning in an update. |
Good luck with this one... Browser profile changes in web have broken things in the iOS app a few times lol I’ve been thinking about this also and I was wondering about having the config.json file point to the server. Then a user could enter the web url which probably makes more sense to them. Then we can grab the config file to get the server url. Not sure if that’s the best approach or not. It’s something that should probably be discussed with web and all the app teams that use web though to agree on a single approach. |
This was the issue I was trying to work around - I still kept it as a fallback cause it works on most setups, I think.
This would be very unfortunate - I hadn't thought of that, but it may certainly be possible.
I didn't say I was happy with my code 🤣
Certainly possible, but isn't the most user-friendly option. I'd prefer to avoid that.
Unfortunately, WebView doesn't really allow this :/
JS files would definitely be easier to hook, but injecting stuff on a minified JavaScript file.. is a recipe for disaster xD What I had thought of would be always requesting an empty script in the webapp index, like
I agree, I'll bring this up in the chat later. |
927de80
to
d52b5e5
Compare
Another try, this solution should be much better. Theoretically, there could be race conditions in the new code because of the dispatch to the UI thread, but I haven't seen any signs of one happening yet, so it should be fine. |
d52b5e5
to
178681c
Compare
Loading the |
const val JS_INJECTION_CODE = """ | ||
!function() { | ||
var scripts = [ | ||
'/native/nativeshell.js', | ||
'/native/apphost.js', | ||
'/native/EventEmitter.js', | ||
'/native/chrome.cast.js', | ||
]; | ||
scripts.forEach(function(src) { | ||
var scriptElement = document.createElement("script"); | ||
scriptElement.type = "text/javascript"; | ||
scriptElement.src = src; | ||
scriptElement.charset = "utf-8"; | ||
scriptElement.setAttribute("defer", ""); | ||
document.body.appendChild(scriptElement); | ||
}); | ||
}(); | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const val JS_INJECTION_CODE = """ | |
!function() { | |
var scripts = [ | |
'/native/nativeshell.js', | |
'/native/apphost.js', | |
'/native/EventEmitter.js', | |
'/native/chrome.cast.js', | |
]; | |
scripts.forEach(function(src) { | |
var scriptElement = document.createElement("script"); | |
scriptElement.type = "text/javascript"; | |
scriptElement.src = src; | |
scriptElement.charset = "utf-8"; | |
scriptElement.setAttribute("defer", ""); | |
document.body.appendChild(scriptElement); | |
}); | |
}(); | |
""" | |
const val JS_INJECTION_CODE = """ | |
!function() { | |
var scripts = [ | |
'/native/nativeshell.js', | |
'/native/apphost.js', | |
'/native/EventEmitter.js', | |
'/native/chrome.cast.js', | |
]; | |
scripts.forEach(function(src) { | |
var scriptElement = document.createElement('script'); | |
scriptElement.type = 'text/javascript'; | |
scriptElement.src = src; | |
scriptElement.charset = 'utf-8'; | |
scriptElement.setAttribute('defer', ''); | |
document.body.appendChild(scriptElement); | |
}); | |
}(); | |
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still prefer a separate file for this but I guess that won't happen 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the overhead just isn't worth it.. I wanted to add a @Language
annotation to inject a language reference, but Android Studio (or IntelliJ CE) doesn't support JavaScript 😤
I'm for some reason not really happy with this yet.. feedback is highly appreciated 😇