-
- 2.1. Built With
- 2.2. Installation
- 2.3. New Repository & Package.json
- 2.4. Your puppeteer script.
- 2.5. Github Action
- 2.6. package.json 'scripts'
This github action was born out of slight frustration that:
- The chromium version that puppeteer uses does not have video codecs installed.
- Most of the puppeteer actions on the marketplace lack any decent documentation. Which meant it was hard to get anything running.
This project was built with the following frameworks, technologies and software.
Create a new github repository and include a package.json file.
/package.json
In the dependencies, you will want to include 'puppeteer-core',
{
"name": "prunner",
"version": "1.0.0",
"author": "Andy Pearson (https://ioroot.com)",
"description": "Allows you to run puppeteer scripts.",
"license": "MIT",
"main": "puppeteer.js",
"dependencies": {
"puppeteer-core": "^5.4.1"
}
}
Next, you'll want to include your own script that will run puppeteer and do whatever it is you want it to do.
/myscript.js
/package.json
This script will need to reference chrome in a specific location: /usr/bin/google-chrome-stable
const puppeteer = require('puppeteer-core');
browser = puppeteer.launch({
headless: true,
devtools: false,
executablePath: "/usr/bin/google-chrome-stable",
args: ['--no-sandbox']
});
You should now be able to run your puppeteer steps in your script.
Lastly, to run the whole process, you need to create a github action workflow file.
/.github/workflows/run_action.yml
/myscript.js
/package.json
This workflow action will include the bare minimum of:
name: Demo puppeteer script
on:
workflow_dispatch:
jobs:
demo:
runs-on: ubuntu-latest
steps:
# Copy contents of this repository into runner.
- uses: actions/checkout@master
# Run the "Args" as a command in the docker container
# created by this action. 'npm install' will run.
- name: Install
uses: IORoot/action__puppeteer--media@master
with:
args: npm install
# Run the "Args" as a command in the docker container
# created by this action. 'node myscript.js' will run
- name: Test Code
uses: IORoot/action__puppeteer--media@master
with:
args: node myscript.js
Instead of running the node myscript.js
in the 'args', you could transfer the execution
into the package.json like so:
{
"name": "prunner",
"version": "1.0.0",
"author": "Andy Pearson (https://ioroot.com)",
"description": "Allows you to run puppeteer scripts.",
"license": "MIT",
"main": "puppeteer.js",
"dependencies": {
"puppeteer-core": "^5.4.1"
},
"scripts": {
"start": "node myscript.js"
}
}
You could then run npm run start
as the command in 'args'.
- name: Test Code
uses: IORoot/action__puppeteer--media@master
with:
args: npm run start
Github Actions.
None.
IMPORTANT - Some puppeteer scripts will not run correctly when using a version of chromium that has NOT been compiled with the video/audio codecs. Chrome comes with them as standard but Chromium does not.
Manually, You can download a copy of Chromium with those codecs here: https://chromium.woolyss.com/ to query these routes.
You can then set the executablePath
of puppeteer-core in the puppeteer settings
to point to this version of chromium.
Warning - If you do not do this, then chromium will not upload any videos because it will not recognise those file formats. Images will work, however.
Why did I need this? Well, I had created a puppeteer script that was navigating to the facebook creator studio and uploading an instagram video. However, it would not work because chrome couldn't handle the MP4 files being uploaded. So a different version was required.
/**
* ISSUE - CHROMIUM NOT ABLE TO UPLOAD VIDEO
*
* https://github.com/puppeteer/puppeteer/issues/291
*
* Chromium cannot upload video, however, Chrome can. This is
* because chromium is compiled without any codec support. Therefore,
* use a chromium version WITH support or use Chrome.
*
* You can download a chromium version here:
* https://chromium.woolyss.com/#mac-stable-ungoogled-marmaduke
*
* Change the executablePath to a google chrome instance
* executablePath: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
*/
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue. Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License.
MIT License
Copyright (c) 2022 Andy Pearson
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Author Link: https://github.com/IORoot
- v1.0.0 - Initial Commit