question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

injectedJavaScript stopped working after 9.0.0

See original GitHub issue

Bug 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:closed
  • Created 4 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

23reactions
redpandatronicsukcommented, Mar 18, 2020

@shirakaba Thanks, when passing an empty function to onMessage it works again.

5reactions
plaacommented, Apr 1, 2020

I had the same issue, and yes, adding an empty onMessage function fixed the issue. But this is documented nowhere! The injectedJavaScript documentation should have a big red box saying that you need to define onMessage as well in order for this to work.

It should also be trivial to check that if injectedJavaScript is defined but onMessage is not, then add an empty onMessage 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found