I'm trying to run a javascript code in an iOS app when a button is clicked.

This is how I'm calling it inside my Swift file, scriptsource being the script in a string.

registrationwebview.evaluateJavaScript(scriptSource, completionHandler: { result, error in
    if let output = result as? String {

This is my js uses a external library called puppeteer.

const puppeteer = require('puppeteer');

(async function main(){
        const browser = await puppeteer.launch({headless: true});
        const page = await browser.newPage();

        page.setUserAgent('Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1')

        await page.goto('https://experts.shopify.com');
        await page.waitForSelector('.section');

        console.log('its showing');
    } catch (e){
        console.log('our error:', e);

I clearly don't need webview anymore so how do I install the puppeteer library in my project and use the js normally without webview?

0 Answers