简体   繁体   English

使用 puppeteer 在无头 chrome 中运行 Flash 游戏

[英]Run flash game in headless chrome using puppeteer

How can I run a flash game in headless chrome using puppeteer?如何使用 puppeteer 在无头 chrome 中运行 Flash 游戏? I'm trying to screenshot this flash game but the game doesn't run and is replaced by "Couldn't load plugin" text.我正在尝试对这个Flash 游戏进行截图,但游戏无法运行,而是被“无法加载插件”文本取代。

Here's the relevant code I used to generate the screenshot and its output, running in ubuntu on windows subsystem linux:这是我用来生成屏幕截图及其输出的相关代码,在 Windows 子系统 linux 上的 ubuntu 中运行:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});
  const page = await browser.newPage();
  await page.setViewport({width: 1243, height: 882});
  await page.goto('http://www.bigfuntown.com/Game-59.html');
  await page.screenshot({path: 'game.png'});

  await browser.close();
})();

在此处输入图片说明

In modern Chrome versions flash is blocked by default and requires user interaction to be enabled. 在现代的Chrome版本中,默认情况下会阻止Flash,并且需要启用用户交互功能。

As this was problematic to automate I've made a puppeteer wrapper for this purpose: puppeteer.setExtra({allowFlash: true}) 由于这在实现自动化方面存在问题,因此我为此制作了一个 puppeteer.setExtra({allowFlash: true}) 包装器puppeteer.setExtra({allowFlash: true})

Note that headless: false is still required due to puppeteer limitations. 请注意, headless: false由于headless: false限制,仍然需要headless: false

You need to enable the Flash plugin . 您需要启用Flash插件


As the official puppeteer documentation states: 官方的伪造者文档所述:

By default, Puppeteer disables extensions when launching Chrome . 默认情况下, Puppeteer在启动Chrome时会禁用扩展程序 You can load a specific extension using: 您可以使用以下方式加载特定的扩展程序:

 const browser = await puppeteer.launch({ headless: false, args: [ '--disable-extensions-except=/path/to/extension/', '--load-extension=/path/to/extension/', ] }); 

Footnote : Note that, depending on the operating system you're using and the way you choose to distribute the Node module/application, this could cause issues of varying degrees. 脚注请注意,这取决于您使用的操作系统以及您选择分发Node模块/应用程序的方式,这可能会引起不同程度的问题。 For instance, if you're on Linux, getting the latest version of Flash running may not be entirely straightforward . 例如,如果您使用的是Linux,则运行最新版本的Flash 可能并不容易 If you need to package it and distribute to clients, that's a horde of issues on its own. 如果您需要打包并将其分发给客户,那么这本身就是一大堆问题。 That, however, is off-topic for this answer, I believe. 但是,我认为,对于这个答案而言,这是偏离主题的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM