Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allowing to run Flash on all sites in Puppeteer

Disclaimer: I know that Flash will be abandoned by the end of 2020, but I simply cannot drop the case and need to have flash in Puppeteer, though I don't like it either.

I need to crawl certain flash sites and take a screenshot of them, for later programatic comparison. I could provide a finite list of domains that I need to check against (though the list may change in time, so it'd be great to be able to somehow load them at the runtime).

Been searching through the Internet after solutions for a while now, the closest I got in matter of SA question is this: how to add urls to Flash white list in puppeteer

I managed to get Flash sites be properly recognized after using puppeteer-extra-plugin-flash, providing path and version for PepperFlash and running Chrome executable instead of Chromium, but I still need to click the greyed out puzzle to allow flash to be run on any website.

I just can't find a solution that will work in July 2019.

I've tried using various arguments:

  --ppapi-in-process || 
  --disable-extensions-except=${pluginPath}/.. || 
  --allow-outdated-plugins || 
  --no-user-gesture-required

And bunch of more, possibly unrelated. The approach that seems most successful for other people seems to be using PluginsAllowedForUrls and providing a list of urls with wildcards, then loading predefined profile via --user-data-dir - but I had not luck in that matter either (I have issues with preparing proper profile I suppose).

This tool that I am building will not be public and be used only internally, by educated team - so I don't have too much security constrains to care about. I simply need the Flash in puppeteer. I also do not need to care about Dockerizing it.

My current setup, simplified:


// within async function

const browser = await puppeteer.launch({
    headless: false,
    executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
    args: [
        '--window-size=800,600',
        '--enable-webgl',
        '--enable-accelerated-2d-canvas',
        `--user-data-dir=${path.join(process.cwd(), 'chrome-user-data')}`
        // '--always-authorize-plugins', -> does not seem to be doing anything in our case
        // '--enable-webgl-draft-extensions', -> does not seem to be doing anything in our case
        // '--enable-accelerated-vpx-decode', -> does not seem to be doing anything in our case
        // '--no-user-gesture-required',  -> does not seem to be doing anything in our case
        // '--ppapi-in-process', -> does not seem to be doing anything in our case
        // '--ppapi-startup-dialog', -> does not seem to be doing anything in our case
        // `--disable-extensions-except=${pluginPath}/..`, -> does not solve issue with blocked
        // '--allow-outdated-plugins', -> does not seem to be doing anything in our case
    ],
});

const context = await browser.defaultBrowserContext();
const page = await context.newPage();

const url = new URL('http://ultrasounds.com');
const response = await fetch(url.href);

await page.setViewport({ width: 800, height: 600});
await page.goto(url.href, { waitUntil: 'networkidle2' });
await page.waitFor(10000);

const screenshot = await page.screenshot({
  encoding: 'binary',
});

Chrome version: 75.0.3770.100, puppeteer-extra: 2.1.3 puppeteer-extra-plugin-flash: 2.13

Any kind of guidance is appreciated, and some working examples would be lovely to have, thanks in advance!

like image 548
wopolow Avatar asked Jul 12 '19 10:07

wopolow


1 Answers

I managed to do it. I've found older Chrome version (65), and got it running with puppeteer-extra.

The versions of the libs that I used and are working:

PepperFlashPlugin version: 32.0.0.223

Google Chrome: 65.0.3325.181

Puppeteer-core: 1.7.0 (check the tags for the corresponding version if you need different than 65)

puppeteer-extra: 2.1.3 puppeteer: 1.0.0

puppeteer-extra-plugin-flash: 2.1.3

Launching the browser looks like this:

const browser = await PuppeteerExtra.launch({
        headless: false,
        executablePath: process.env.CHROME_EXECUTABLE,
        args: [
          '--window-size=800,600',
          '--enable-webgl',
          '--enable-accelerated-2d-canvas',
        ],
      });
const page = await this.fBrowser.newPage();

      await page.setViewport({ width: 800, height: 600});
      await page.goto('http://ultrasounds.com', { waitUntil: 'networkidle2' });

And it works! 🎉

like image 100
wopolow Avatar answered Sep 21 '22 18:09

wopolow