如何使节点环境代码在网站上在线工作?
how to make node environment code work on websites online?
我是 vanilla js 的新手(来自 node.js)我想弄清楚如何在我的在线托管网站上显示它
有什么工具可以让它在网页上运行吗
这是简单的 puppeteer 演示代码(来自文档),我需要 运行 在我的网页中
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://apod.nasa.gov/apod/ap150102.html', {
waitUntil: 'networkidle0',
});
await page.waitForTimeout(2000)
await page.waitForSelector('img');
// await page.waitForInterval(2000)
await page.pdf({ path: 'filez.pdf', format: 'a3', fullPage: true });
await browser.close();
})();
实际上,puppeteer 是一个无头的 Chrome (Chromium) 浏览器包装器,它会打开一个 Chrome 实例并使用其 API 来自动化诸如 UI 测试之类的事情, ETC。
无法在客户端使用它。
正如他们在 docs 中提到的那样:
Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. Puppeteer runs headless by default, but can be configured to run full (non-headless) Chrome or Chromium.
我是 vanilla js 的新手(来自 node.js)我想弄清楚如何在我的在线托管网站上显示它
有什么工具可以让它在网页上运行吗
这是简单的 puppeteer 演示代码(来自文档),我需要 运行 在我的网页中
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://apod.nasa.gov/apod/ap150102.html', {
waitUntil: 'networkidle0',
});
await page.waitForTimeout(2000)
await page.waitForSelector('img');
// await page.waitForInterval(2000)
await page.pdf({ path: 'filez.pdf', format: 'a3', fullPage: true });
await browser.close();
})();
实际上,puppeteer 是一个无头的 Chrome (Chromium) 浏览器包装器,它会打开一个 Chrome 实例并使用其 API 来自动化诸如 UI 测试之类的事情, ETC。 无法在客户端使用它。
正如他们在 docs 中提到的那样:
Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. Puppeteer runs headless by default, but can be configured to run full (non-headless) Chrome or Chromium.