npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

electron-puppeteer-project

v1.3.1

Published

electron webview driver like puppeteer

Downloads

1

Readme

electron-puppeteer

electron webview 的驱动,Api 和 puppeteer 高度相似

效果预览

预览图

基础使用

注意 webview.preload.js 必须是fileasar协议

// set the script type="module"
const path = require("path")
const electronPuppeteer = require("electron-puppeteer").default

async function run() {
  // open a browser
  const browser = await electronPuppeteer.launch({
    // container must has height, example: `<div id="container" style="height: 100vh"></div>`
    container: document.getElementById("container"),
    startUrl: "https://segmentfault.com/",
    createPage: true,
    partition: "persist:test",
    // webview.preload.js的路径
    preload:
      "file://" +
      path.join(
        __dirname,
        "node_modules/electron-puppeteer/preload/webview.preload.js",
      ),
  })

  const pages = await browser.pages()
  const page = pages[0]
  // input search text
  let $search = await page.$("#searchBox")
  let word = "electron"
  for (let i = 0; i < word.length; i++) {
    let c = word.charAt(i)
    await $search.press(c)
  }
  // click search button
  await page.click(".header-search button")

  const page2 = await browser.newPage()
  await page2.goto("https://segmentfault.com/blogs")
}

run()

切换多个 browser

  const path = require("path")
  import electronPuppeteer from "./node_modules/electron-puppeteer/renderer/index.js"

  const browserMap = new Map()
  function showBrowser(name) {
    const browser = browserMap.get(name)
    if (!browser) {
      browser = await electronPuppeteer.launch({
        container: document.getElementById('container'),
        preload: "file://" +
          path.join(
            __dirname,
            "node_modules/electron-puppeteer/preload/webview.preload.js",
          ),
      })
      // do something
    }
    browser.bringToFront()
  }

Api

Demo

node 版本建议在 v11+

  1. 到 demo 目录运行npm install
  2. 运行 npm start

注意事项

所属 BrowserWindow 的 webPreferences.nodeIntegration 需要为 true,否则无法获取和操作 webivew 下的 iframe
所属 BrowserWindow 的 webPreferences.devtools 不能为 false,否则 launch 时传入 devtools 将无效
launch 时传入的 webPreferences 属性都必须在 BrowserWindow 内配置,否则无法单独生效