javascript - 如何使用 Puppeteer 设置、更改或阻止时区(系统时间)?

标签 javascript node.js google-chrome google-chrome-devtools puppeteer

  • 操作系统:基于 Windows 10 Pro x64 的 PC
  • Node -v:v8.12.0
  • npm list puppeteer: `-- puppeteer@1.9.0

  • 我试过这个:
    puppeteer.launch({
      env: {
        TZ: 'Australia/Melbourne',
        ...process.env
      }
    });
    

    不要为我工作。 whoer.net 看到我的实际系统时间。

    编辑:关于 https://github.com/nodejs/node/issues/4230 的一些信息

    This code works well on Linux but does not work on Windows:


    process.env.TZ = 'UTC';
    
    console.log(new Date());
    

    On Windows, I see timezone from my OS.

    最佳答案

    根据Puppeteer documentation , 你可以使用 page.emulateTimezone() :

    page.emulateTimezone()

    timezoneId <?string> Changes the timezone of the page. See ICU’s metaZones.txt for a list of supported timezone IDs. Passing null disables timezone emulation.

    returns: <Promise>



    例如:
    await page.emulateTimezone('America/Chicago');
    

    关于javascript - 如何使用 Puppeteer 设置、更改或阻止时区(系统时间)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53027538/

    相关文章:

    browser - 跨子域/端口 socket.io - 如何处理?

    javascript - CORS 使用浏览器的 session cookie 获取身份验证

    css - Android UI 遮挡了 Chrome `position:fixed; bottom: 0;`

    javascript - 如何更新 Mongoose 嵌套数组文档

    javascript - JSON 中的对象使用 $Each 循环,如何获取值

    javascript - 如何在点击时显示每个类元素?

    javascript - 带有构造函数和其他对象的 Module.exports

    javascript - 用于查找唯一文档的 Mongoose 查询

    javascript - Android 在滚动事件更新内容时设置 scrollLeft 不更新滚动条位置

    javascript - 如何将列插入网页