File tree 2 files changed +9
-5
lines changed
2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -3,18 +3,22 @@ import {Stores} from './store/model';
3
3
import { Logger } from './logger' ;
4
4
import { sendNotification } from './notification' ;
5
5
import { lookup } from './store' ;
6
+ import puppeteer from 'puppeteer' ;
6
7
7
8
/**
8
9
* Starts the bot.
9
10
*/
10
11
async function main ( ) {
11
12
const results = [ ] ;
13
+ const browser = await puppeteer . launch ( ) ;
14
+
12
15
for ( const store of Stores ) {
13
16
Logger . debug ( store . links ) ;
14
- results . push ( lookup ( store ) ) ;
17
+ results . push ( lookup ( browser , store ) ) ;
15
18
}
16
19
17
20
await Promise . all ( results ) ;
21
+ await browser . close ( ) ;
18
22
19
23
Logger . info ( '↗ trying stores again' ) ;
20
24
setTimeout ( main , Config . rateLimitTimeout ) ;
Original file line number Diff line number Diff line change @@ -24,16 +24,16 @@ function filterBrand(brand: string) {
24
24
* a `Store`. It's important that we ignore `no-await-in-loop` here
25
25
* because we don't want to get rate limited within the same store.
26
26
*
27
+ * @param browser Current browser in use.
27
28
* @param store Vendor of graphics cards.
28
29
*/
29
- export async function lookup ( store : Store ) {
30
+ export async function lookup ( browser : puppeteer . Browser , store : Store ) {
30
31
/* eslint-disable no-await-in-loop */
31
32
for ( const link of store . links ) {
32
33
if ( ! filterBrand ( link . brand ) ) {
33
34
continue ;
34
35
}
35
36
36
- const browser = await puppeteer . launch ( ) ;
37
37
const page = await browser . newPage ( ) ;
38
38
page . setDefaultNavigationTimeout ( Config . page . navigationTimeout ) ;
39
39
await page . setUserAgent ( Config . page . userAgent ) ;
@@ -48,7 +48,7 @@ export async function lookup(store: Store) {
48
48
await page . goto ( link . url , { waitUntil : 'networkidle0' } ) ;
49
49
} catch {
50
50
Logger . error ( `✖ [${ store . name } ] ${ graphicsCard } skipping; timed out` ) ;
51
- await browser . close ( ) ;
51
+ await page . close ( ) ;
52
52
continue ;
53
53
}
54
54
@@ -79,7 +79,7 @@ export async function lookup(store: Store) {
79
79
sendNotification ( givenUrl ) ;
80
80
}
81
81
82
- await browser . close ( ) ;
82
+ await page . close ( ) ;
83
83
}
84
84
/* eslint-enable no-await-in-loop */
85
85
}
You can’t perform that action at this time.
0 commit comments