-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathutil.ts
103 lines (90 loc) · 2.63 KB
/
util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import {Browser, launch} from 'puppeteer';
import {config} from '../src/config';
import {logger} from '../src/logger';
import {Link, Store} from '../src/store/model';
export function getTestLink(): Link {
const link: Link = {
brand: 'test:brand',
cartUrl: 'https://www.example.com/cartUrl',
model: 'test:model',
price: 100,
series: 'test:series',
url: 'https://www.example.com/url',
};
return link;
}
export function getCaptchaTestLink(): Link {
const link: Link = {
brand: 'test:brand',
cartUrl:
'https://upload.wikimedia.org/wikipedia/en/thumb/f/f7/RickRoll.png/250px-RickRoll.png',
model: 'test:model',
price: 100,
series: 'test:series',
url: 'https://en.wikipedia.org/wiki/Rickrolling',
};
return link;
}
export function getTestStore(): Store {
const storeLinks = [getTestLink(), getCaptchaTestLink()];
const store: Store = {
currency: '',
labels: {
captcha: {
container: '#firstHeading',
text: ['Rickrolling'],
},
captchaHandler: {
challenge: 'img.thumbimage',
input: '#searchInput',
submit: 'body',
captureType: 'image',
},
inStock: {
container: 'test:container',
text: ['test:text'],
},
},
links: storeLinks,
name: 'test:name',
};
return store;
}
export async function launchTestBrowser(): Promise<Browser> {
const args: string[] = [];
// Skip Chromium Linux Sandbox
// https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#setting-up-chrome-linux-sandbox
if (config.browser.isTrusted) {
args.push('--no-sandbox');
args.push('--disable-setuid-sandbox');
}
// https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#tips
// https://stackoverflow.com/questions/48230901/docker-alpine-with-node-js-and-chromium-headless-puppeter-failed-to-launch-c
if (config.docker) {
args.push('--disable-dev-shm-usage');
args.push('--no-sandbox');
args.push('--disable-setuid-sandbox');
args.push('--headless');
args.push('--disable-gpu');
config.browser.open = false;
}
// Add the address of the proxy server if defined
if (config.proxy.address) {
args.push(
`--proxy-server=${config.proxy.protocol}://${config.proxy.address}:${config.proxy.port}`
);
}
if (args.length > 0) {
logger.info('ℹ puppeteer config: ', args);
}
const browser = await launch({
args,
defaultViewport: {
height: config.page.height,
width: config.page.width,
},
headless: config.browser.isHeadless,
});
config.browser.userAgent = await browser.userAgent();
return browser;
}