I want to instantiate a class called DataBinding that uses document.querySelector inside a CoffeeScript file. To achieve this, I'm using Puppeteer to create the DOM environment. However, inside page.evaluate, the code didn't recognize the class DataBinding. I'm performing this to test the DataBinding class. I tried to run the following code, but it didn't work:
import puppeteer from 'puppeteer'
import { DataBinding } from // correct path
browser = await puppeteer.launch({headless: 'new', executablePath: "/usr/bin/google-chrome-stable"});
page = await browser.newPage();
await page.goto 'http://127.0.0.1:9000';
await page.evaluate(() =>
data_binding_instance = new DataBinding();
)
await browser.close();
- I'm running a blank
index.htmlpage just to create the DOM. - This code is transpiled by esbuild to generate a .js file.
- I'm running the transpiled code with
node test_data_binding.js(where test_data_binding.js is the transpiled file).
I tried a lot of things, such as using page.exposeFunction to pass a function to the Puppeteer context that returns a DataBinding class, but it didn't work.