|
|
@@ -1,6 +1,13 @@
|
|
|
import { chromium } from "playwright";
|
|
|
import uniqueRandomArray from "unique-random-array";
|
|
|
import userAgents from "top-user-agents";
|
|
|
+import { dirname, resolve, join } from "path";
|
|
|
+import { fileURLToPath } from "url";
|
|
|
+import fs from "fs";
|
|
|
+import stringHash from "string-hash";
|
|
|
+
|
|
|
+const __filename = fileURLToPath(import.meta.url);
|
|
|
+const __dirname = dirname(__filename);
|
|
|
|
|
|
export async function login(email, password, proxy) {
|
|
|
const browser = await chromium.launch({
|
|
|
@@ -29,16 +36,39 @@ export async function login(email, password, proxy) {
|
|
|
|
|
|
let points = null;
|
|
|
|
|
|
- await page.route(/points$/, async (route, request) => {
|
|
|
+ await context.route(/points$/, async (route, request) => {
|
|
|
const response = await route.fetch();
|
|
|
points = await response.text();
|
|
|
await route.continue();
|
|
|
});
|
|
|
- await page.route(
|
|
|
- /(\.png)|(\.jpg)|(\.svg)|(\.otf)|(\.woff2)|(\.ttf)|(\.mp3)/gi,
|
|
|
- (route) => route.abort()
|
|
|
+
|
|
|
+ await context.route(
|
|
|
+ /(\.png)|(\.jpg)|(\.svg)|(\.otf)|(\.woff)|(\.woff2)|(\.ttf)|(\.mp3)/,
|
|
|
+ (route, request) => route.abort()
|
|
|
);
|
|
|
|
|
|
+ await context.route(/(\.js)|(\.css)/, async (route, request) => {
|
|
|
+ const fileName = resolve(
|
|
|
+ __dirname,
|
|
|
+ "cache",
|
|
|
+ "" + stringHash(request.url())
|
|
|
+ );
|
|
|
+ if (fs.existsSync(fileName)) {
|
|
|
+ await route.fulfill({
|
|
|
+ body: fs.readFileSync(fileName),
|
|
|
+ contentType: /\.js$/.test(request.url())
|
|
|
+ ? "application/javascript"
|
|
|
+ : "text/css",
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ const response = await route.fetch();
|
|
|
+ fs.writeFileSync(fileName, await response.body());
|
|
|
+ await route.fulfill({
|
|
|
+ response,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
await page.goto("https://www.pcoptimum.ca/");
|
|
|
|
|
|
const link = await page.$('a > span:has-text("sign in")');
|