Cap-go / capacitor-inappbrowser

Capacitor plugin in app browser with urlChangeEvent
MIT License
71 stars 52 forks source link

bug: executeScript Not Working in InAppBrowser #234

Open thibaut129 opened 8 hours ago

thibaut129 commented 8 hours ago

Version

6.9.13

Platform(s)

Current behavior

Hi, I'm a new user of this wonderful plugin but I have an issue. I encountered an issue where the executeScript method does not work as expected. When trying to execute a script in the InAppBrowser’s WebView, nothing happens. The script does not execute, and no error is logged.

Expected behavior

The executeScript method should inject the provided script (alert('Hello from the website!');) into the WebView and execute it.

Reproduction

No response

Steps to reproduce

async openWebsite() {
  await InAppBrowser.openWebView({
    url: 'https://www.google.fr/'
  });

  await InAppBrowser.addListener('urlChangeEvent', (data) => {
    console.log('URL changed:', data.url);
    // alert('URL changed:' + data.url);
  });

  await InAppBrowser.executeScript({
    code: `alert('Hello from the website!');`
  });
}

Other information

I test it on an Xcode iOs Simulator : Here the output : ⚡️ To Native -> InAppBrowser openWebView 655573 ⚡️ TO JS undefined ⚡️ TO JS {"url":"https:\/\/www.google.fr\/"} ⚡️ TO JS {"url":"https:\/\/www.google.fr\/"} ⚡️ TO JS {"url":"https:\/\/www.google.fr\/"} ⚡️ TO JS {"url":"https:\/\/www.google.fr\/"} ⚡️ To Native -> InAppBrowser addListener 655574 ⚡️ To Native -> InAppBrowser executeScript 655575 ⚡️ TO JS undefined ⚡️ [log] - URL changed: https://www.google.fr/ ⚡️ TO JS undefined

Capacitor doctor

[warn] The bundledWebRuntime configuration option has been deprecated. Can be safely deleted. 💊 Capacitor Doctor 💊

Latest Dependencies:

@capacitor/cli: 6.1.2 @capacitor/core: 6.1.2 @capacitor/android: 6.1.2 @capacitor/ios: 6.1.2

Installed Dependencies:

@capacitor/cli: 6.1.2 @capacitor/core: 6.1.2 @capacitor/android: 6.1.2 @capacitor/ios: 6.1.2

[info] Using Gemfile: RubyGems bundle installed [success] iOS looking great! 👌 [success] Android looking great! 👌

Before submitting

Fastest way to fix this issue

thibaut129 commented 7 hours ago

Working on android with simulator