Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit c9a23cd

Browse files
committed
Initial commit
0 parents commit c9a23cd

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Heroku Playwright Buildpack
2+
3+
This buildpack installs all the needed dependencies to use Playwright with Chromium and Firefox on Heroku.
4+
5+
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/mxschmitt/heroku-playwright-example)
6+
7+
## Usage
8+
9+
For using this buildpack, you have to add the buildpack **before** installing your Node.js dependencies.
10+
11+
```txt
12+
heroku buildpacks:set https://github.com/mxschmitt/heroku-playwright-example -a my-app
13+
```
14+
15+
For a full example, see [here](https://github.com/mxschmitt/heroku-playwright-example) a usage with the Express library.
16+
17+
## Best practises
18+
19+
It's common to only install the [browser-specific NPM packages](https://playwright.dev/#version=v1.1.1&path=docs%2Finstallation.md&q=download-single-browser-binary), which will reduce installation time and slug size on Heroku in the end, that should fix also the error that the slug size is too large.

bin/compile

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
BUILD_DIR=$1
6+
CACHE_DIR=$2
7+
ENV_DIR=$3
8+
BP_DIR=`cd $(dirname $0); cd ..; pwd`
9+
10+
error() {
11+
echo " ! $*" >&2
12+
exit 1
13+
}
14+
15+
topic() {
16+
echo "-----> $*"
17+
}
18+
19+
install_system_deps() {
20+
topic "Installing System Dependencies"
21+
22+
APT_BUILDPACK="https://github.com/heroku/heroku-buildpack-apt"
23+
local buildpack_tmpdir=$(mktemp -d)
24+
cd $buildpack_tmpdir && git clone $APT_BUILDPACK .
25+
26+
local build_tmpdir=$(mktemp -d)
27+
mkdir -p $build_tmpdir
28+
cat << EOF >$build_tmpdir/Aptfile
29+
# WebKit dependencies
30+
#libwoff1
31+
#libopus0
32+
#libwebp6
33+
#libwebpdemux2
34+
#libenchant1c2a
35+
#libgudev-1.0-0
36+
#libsecret-1-0
37+
#libhyphen0
38+
libgdk-pixbuf2.0-0
39+
#libegl1
40+
libnotify4
41+
#libxslt1.1
42+
#libevent-2.1-6
43+
#libgles2
44+
#libvpx5
45+
# gstreamer and plugins to support video playback in WebKit
46+
#gstreamer1.0-gl
47+
#gstreamer1.0-plugins-base
48+
#gstreamer1.0-plugins-good
49+
#gstreamer1.0-plugins-bad
50+
# Chromium dependencies
51+
libnss3
52+
libxss1
53+
libasound2
54+
fonts-noto-color-emoji
55+
libcairo-gobject2
56+
# Firefox dependencies
57+
libdbus-glib-1-2
58+
libxt6
59+
libsm6
60+
libice6
61+
# FFmpeg to bring in audio and video codecs necessary for playing videos in Firefox
62+
ffmpeg
63+
# (Optional) XVFB if there's a need to run browsers in headful mode
64+
xvfb
65+
EOF
66+
67+
local cache_tmpdir=$(mktemp -d)
68+
69+
HOME=/app $buildpack_tmpdir/bin/compile $build_tmpdir $cache_tmpdir
70+
if [ $? -ne 0 ]; then
71+
rm -rf $buildpack_tmpdir $build_tmpdir $cache_tmpdir
72+
error "Could not install dependencies"
73+
fi
74+
mv $build_tmpdir/.apt $BUILD_DIR
75+
# mv file in case user is using .profile.d
76+
mkdir -p $BUILD_DIR/.profile.d/
77+
mv $build_tmpdir/.profile.d/000_apt.sh $BUILD_DIR/.profile.d/
78+
79+
rm -rf $buildpack_tmpdir $build_tmpdir $cache_tmpdir
80+
}
81+
82+
configure_export_env() {
83+
topic "Writing profile script"
84+
mkdir -p $BUILD_DIR/.profile.d
85+
cat << EOF >$BUILD_DIR/.profile.d/001_playwright.sh
86+
export PLAYWRIGHT_BROWSERS_PATH=0
87+
EOF
88+
89+
# Give environment variable to other buildpacks
90+
echo "export PLAYWRIGHT_BROWSERS_PATH=0" >> "$BP_DIR/export"
91+
92+
export PLAYWRIGHT_BROWSERS_PATH=0
93+
}
94+
95+
install_system_deps
96+
configure_export_env

bin/detect

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
echo "Playwright"
4+
exit 0

0 commit comments

Comments
 (0)