Update 25/6/23:

I went back to a previous version of my app and this works, so it's clearly something that I've changed in the last 6 months.

Original:

When I try to call executeScript on a Twitter page I've opened in Ionic's @ionic-native/in-app-browser on an Android emulator I get this error from that webpage:

Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' <and then some url's with wildcards which SO won't let me include in my question>".

I am trying to open the page like this:

options = "location=yes,closebuttoncaption=" + buttonWording + ",usewkwebview=yes";
this.browserpopup = this.iab.create(this.temp_selected_link, '_blank', options);
this.browserpopup.on('loadstop').subscribe(event => {
      console.log('loadstop: event = ', event);
      console.log('About to call: this.browserpopup.executeScript');
      this.browserpopup.executeScript({
        code: "(function myFunction() { setTimeout(myFunction, 1000); const returnObject = {'url': '' } returnObject.url = window.location.href; return returnObject;} )()"
// I've cut down the code for brevity
      }, (returnObject) => {
        this.returnObject = returnObject;
        console.log('loadstop: returnObject = ', returnObject);
      })
    });

I am expecting returnObject to log to the console every second. Instead I get the error above logged every second.

This works with other web pages, but Twitter throws this error.

It has worked with Twitter in the past, but I guess they have changed their CSP policy.

I've tried calling executeScript on a window.open object, as per this issue but then I get an error that executeScript is not a function of window.

ionic info:

Ionic:

   Ionic CLI                     : 7.1.1 
   Ionic Framework               : @ionic/angular 6.2.2
   @angular-devkit/build-angular : 14.1.2
   @angular-devkit/schematics    : 14.1.2
   @angular/cli                  : 14.1.2
   @ionic/angular-toolkit        : 2.3.3

Cordova:

   Cordova CLI       : 12.0.0 ([email protected])
   Cordova Platforms : android 11.0.0, ios 6.2.0
   Cordova Plugins   : cordova-plugin-ionic-webview 5.0.0, (and 18 other plugins)

Utility:

   cordova-res : 0.15.4
   native-run  : 1.7.2

System:

   Android SDK Tools : 26.1.1
   NodeJS            : v16.14.0
   npm               : 8.3.1
   OS                : Windows 10

ionic cordova plugin ls:

com.telerik.plugins.nativepagetransitions 0.6.5 "Native Page Transitions"
cordova-admob-sdk 0.24.1 "AdMob SDK"
cordova-plugin-admob-free 0.27.0 "Cordova AdMob Plugin"
cordova-plugin-androidx-adapter 1.1.3 "cordova-plugin-androidx-adapter"
cordova-plugin-background-mode 0.7.3 "BackgroundMode"
cordova-plugin-badge 0.8.8 "Badge"
cordova-plugin-buildinfo 4.0.0 "BuildInfo"
cordova-plugin-camera 4.1.0 "Camera"
cordova-plugin-customurlscheme 5.0.2 "Custom URL scheme"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-file-transfer 1.7.1 "File Transfer"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-firebase-messaging 7.0.4 "FirebaseMessagingPlugin"
cordova-plugin-inappbrowser 5.0.0 "InAppBrowser"
cordova-plugin-ionic-webview 5.0.0 "cordova-plugin-ionic-webview"
cordova-plugin-safariviewcontroller 2.0.0 "SafariViewController"
cordova-plugin-sign-in-with-apple 0.1.2 "cordova-plugin-sign-in-with-apple"
cordova-plugin-splashscreen 5.0.3 "Splashscreen"
cordova-plugin-statusbar 2.4.3 "StatusBar"
cordova-promise-polyfill 0.0.2 "cordova-promise-polyfill"
cordova-support-android-plugin 2.0.4 "cordova-support-android-plugin"

Any suggestions on how to make this work appreciated. Or any alternative approaches to bee able to retrieve data from a Twitter page within inAppBrowser.

0

There are 0 answers