Skip to content

Commit 5c823f5

Browse files
authored
Merge pull request #39 from dev-protocol/bots
Using `puppeteer-extra-plugin-stealth`
2 parents c2b519b + 50fbd65 commit 5c823f5

File tree

6 files changed

+432
-201
lines changed

6 files changed

+432
-201
lines changed

.github/workflows/build.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ name: Release
22

33
on:
44
release:
5-
types: [published, prereleased]
5+
types: [published]
66

77
permissions:
88
contents: write
99
pull-requests: write
1010

11+
env:
12+
ZIP_LAMBDA: lambda-${{github.event.release.tag_name}}.zip
13+
ZIP_CHROMIUM: chromium-${{github.event.release.tag_name}}.zip
14+
ZIP_LIBS: libs-${{github.event.release.tag_name}}.zip
15+
ZIP_FONTS: fonts-${{github.event.release.tag_name}}.zip
16+
1117
jobs:
1218
upload-artifact:
1319
runs-on: ubuntu-latest
@@ -32,40 +38,40 @@ jobs:
3238
run: |
3339
yarn build
3440
echo '{"type": "module"}' > dist/package.json
35-
zip -rj lambda.zip dist
41+
zip -rj ${{env.ZIP_LAMBDA}} dist
3642
3743
- name: Build `chromium` layer
3844
run: |
3945
mkdir work-chromium
4046
cd work-chromium
4147
git clone --depth=1 https://github.com/sparticuz/chromium.git
4248
cd chromium
43-
make chromium.zip
44-
mv chromium.zip ../../
49+
make ${{env.ZIP_CHROMIUM}}
50+
mv ${{env.ZIP_CHROMIUM}} ../../
4551
4652
- name: Build `libs` layer
4753
run: |
4854
mkdir nodejs
4955
rm -rf node_modules
5056
yarn workspaces focus --production
5157
cp -r node_modules nodejs
52-
zip -r libs.zip nodejs
58+
zip -r ${{env.ZIP_LIBS}} nodejs
5359
5460
- name: Build `fonts` layer
5561
run: |
5662
mkdir work-fonts
5763
cd work-fonts
5864
git clone --depth=1 https://github.com/dev-protocol/stackroom.git
5965
cd stackroom/fonts
60-
mv IBM_Plex_Sans_JP/* ./
66+
mv IBM_Plex_Sans_JP/IBMPlexSansJP-Bold.ttf ./
6167
rm -rf IBM_Plex_Sans_JP
6268
mv Noto_Color_Emoji/* ./
6369
rm -rf Noto_Color_Emoji
6470
cd ../
65-
zip -r fonts.zip fonts
66-
mv fonts.zip ../../
71+
zip -r ${{env.ZIP_FONTS}} fonts
72+
mv ${{env.ZIP_FONTS}} ../../
6773
6874
- name: Upload Artifact
6975
env:
7076
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71-
run: gh release upload ${{ github.event.release.tag_name }} lambda.zip chromium.zip libs.zip fonts.zip
77+
run: gh release upload ${{ github.event.release.tag_name }} ${{env.ZIP_LAMBDA}} ${{env.ZIP_CHROMIUM}} ${{env.ZIP_LIBS}} ${{env.ZIP_FONTS}}

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "template-repos-ts",
3-
"version": "2.0.4",
3+
"version": "2.1.0-beta.4",
44
"description": "Template repository for using TypeScript",
55
"type": "module",
66
"scripts": {
@@ -14,10 +14,10 @@
1414
"author": "Dev Protocol",
1515
"license": "MPL-2.0",
1616
"dependencies": {
17-
"@devprotocol/util-ts": "^4.0.0",
1817
"@sparticuz/chromium": "^132.0.0",
19-
"aws-lambda": "^1.0.7",
20-
"puppeteer-core": "23.6.0"
18+
"puppeteer-core": "^24.2.0",
19+
"puppeteer-extra": "^3.3.6",
20+
"puppeteer-extra-plugin-stealth": "^2.11.2"
2121
},
2222
"devDependencies": {
2323
"@eslint/js": "^9.12.0",
@@ -30,6 +30,7 @@
3030
"@types/eslint-config-prettier": "^6.11.3",
3131
"@types/eslint__js": "^8.42.3",
3232
"@types/node": "22.7.9",
33+
"aws-lambda": "1.0.7",
3334
"dotenv": "16.4.5",
3435
"eslint": "^9.12.0",
3536
"eslint-config-prettier": "^9.1.0",

src/index.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ export const handler: Handler = async ({
6060
const browser = await Chromium.getInstance(options)
6161
const page = await browser.newPage()
6262

63-
// set the viewport size
64-
await page.setViewport({
65-
width: width ? Math.abs(parseInt(width)) : 1920,
66-
height: height ? Math.abs(parseInt(height)) : 1080,
67-
deviceScaleFactor: 1,
68-
})
69-
70-
await page.setRequestInterception(true)
63+
await Promise.all([
64+
// set the viewport size
65+
page.setViewport({
66+
width: width ? Math.abs(parseInt(width)) : 1920,
67+
height: height ? Math.abs(parseInt(height)) : 1080,
68+
deviceScaleFactor: 1,
69+
}),
70+
page.setRequestInterception(true),
71+
])
7172

7273
// eslint-disable-next-line functional/no-return-void
7374
page.on('request', (req) => {

src/libs/chromium.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import type { Browser, PuppeteerLaunchOptions } from 'puppeteer-core'
2-
import puppeteer from 'puppeteer-core'
2+
import puppeteer from 'puppeteer-extra'
3+
import StealthPlugin from 'puppeteer-extra-plugin-stealth'
4+
5+
// eslint-disable-next-line functional/no-expression-statements
6+
puppeteer.use(StealthPlugin())
37

48
export const Chromium = (() => {
59
const instances: WeakMap<PuppeteerLaunchOptions, Browser> = new WeakMap()

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"module": "nodenext",
3+
"module": "es2022",
44
"lib": ["esnext"],
55
"target": "esnext",
66
"outDir": "dist",
@@ -9,6 +9,6 @@
99
"strict": true,
1010
"esModuleInterop": true,
1111
"skipLibCheck": true,
12-
"moduleResolution": "nodenext"
12+
"moduleResolution": "bundler"
1313
}
1414
}

0 commit comments

Comments
 (0)