injectedJavaScript stopped working after 9.0.0
See original GitHub issueBug description:
The injectedJavaScript
parameter no longer works.
To Reproduce:
This used to work:
<WebView injectedJavaScript={`try{var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var oscillator = audioCtx.createOscillator();
oscillator.type = 'sine';
oscillator.frequency.setValueAtTime(420, audioCtx.currentTime);
oscillator.start();
var oscillator_volume = audioCtx.createGain();
oscillator_volume.gain.linearRampToValueAtTime(1, 0);
oscillator.connect(oscillator_volume);
oscillator_volume.connect(audioCtx.destination);
}catch(e){}
true;`} />
but no longer does. Expected behavior:
That the above js code gets ejected into the WebView, executes and plays the sound created by the oscillator.
Screenshots/Videos:
Environment:
- OS: iOS
- OS version:
- react-native version:
- react-native-webview version:
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
react-native-webview how to inject javascript? - Stack Overflow
Try to inject js like this way: const jsCode = `document.querySelector('.HeaderHero').style.backgroundColor = 'purple';`; return ( <View ...
Read more >react-native-webview - npm
Start using react-native-webview in your project by running `npm i ... 9.0.0 - props updates to injectedJavaScript are no longer immutable.
Read more >Release Notes - codeBeamer - 9.0.x
Jira bi-Directional implementation was completely refactored in 9.0.0 and old style project dependent implementation is deprecated and not supported anymore ...
Read more >Enterprise Mail Handler for Jira (JEMH) - Version history
Browse the top apps, add-ons, plugins & integrations for Jira, Confluence, Bitbucket, Hipchat & other Atlassian products. Free 30-day trial for all apps....
Read more >React Native Webview Not Resetting Injected Javascript
injectedJavaScript doesnt seem to work on IOS Issue #1291 React Native WebView injectedJavaScript stopped working after 9.0.0 Issue #1260.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@shirakaba Thanks, when passing an empty function to
onMessage
it works again.I had the same issue, and yes, adding an empty
onMessage
function fixed the issue. But this is documented nowhere! TheinjectedJavaScript
documentation should have a big red box saying that you need to defineonMessage
as well in order for this to work.It should also be trivial to check that if
injectedJavaScript
is defined butonMessage
is not, then add an emptyonMessage
in the lib itself, which would fix this issue once and for all.Please open this issue and fix it or at least document it.