Skip to content

Commit 6879074

Browse files
committed
chore: Added VSCode debug support
1 parent f707f11 commit 6879074

File tree

6 files changed

+92
-8
lines changed

6 files changed

+92
-8
lines changed

.vscode/launch.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
// Use o IntelliSense para saber mais sobre os atributos possíveis.
3+
// Focalizar para exibir as descrições dos atributos existentes.
4+
// Para obter mais informações, acesse: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "pwa-chrome",
9+
"request": "attach",
10+
"name": "Launch local",
11+
"address": "127.0.0.1",
12+
"port": 9222,
13+
"webRoot": "${workspaceFolder}",
14+
"pathMapping": {
15+
"/dist": "${workspaceFolder}/dist",
16+
"/": "${workspaceFolder}/wa-source"
17+
},
18+
"preLaunchTask": "npm: watch",
19+
"timeout": 30000,
20+
"restart": true,
21+
"server": {
22+
"command": "npm run launch:local \"--\" \"--remote-debugging-port=9222\""
23+
}
24+
}
25+
]
26+
}

.vscode/tasks.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "npm",
6+
"script": "watch",
7+
"group": "build",
8+
"isBackground": true,
9+
"problemMatcher": {
10+
"owner": "Webpack (Dev, Continuous)",
11+
"severity": "error",
12+
"fileLocation": "absolute",
13+
"source": "webpack-typescript",
14+
"background": {
15+
"activeOnStart": true,
16+
"beginsPattern": "assets by path|building|sealing",
17+
"endsPattern": "webpack [\\d.]+ compiled"
18+
},
19+
"pattern": [
20+
{
21+
"regexp": "ERROR in ([^\\(]*)\\((\\d+),(\\d+)\\):",
22+
"file": 1,
23+
"line": 2,
24+
"column": 2
25+
},
26+
{
27+
"regexp": "([A-Za-z0-9-]+):(.*)",
28+
"message": 2,
29+
"code": 1
30+
}
31+
]
32+
},
33+
"label": "npm: watch",
34+
"detail": "webpack watch"
35+
}
36+
]
37+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"wa-source:download": "ts-node ./src/tools/extractWhatsappSource.ts",
3333
"wa-source:format": "prettier --write ./wa-source",
3434
"wa-source": "npm run wa-source:clean && npm run wa-source:download && npm run wa-source:format",
35-
"watch": "webpack --watch --devtool inline-source-map --mode development"
35+
"watch": "webpack watch --devtool inline-source-map --mode development --progress"
3636
},
3737
"dependencies": {},
3838
"devDependencies": {

src/tools/browser.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ import * as waVersion from '@wppconnect/wa-version';
1818
import * as fs from 'fs';
1919
import * as path from 'path';
2020
import * as playwright from 'playwright';
21-
import { LaunchOptions } from 'playwright';
2221

2322
export const URL = 'https://web.whatsapp.com/';
2423
export const WA_DIR = path.resolve(__dirname, '../../wa-source');
2524

26-
export async function getPage(options?: LaunchOptions) {
25+
type LaunchArguments = Parameters<
26+
typeof playwright.chromium.launchPersistentContext
27+
>;
28+
29+
export async function getPage(options?: LaunchArguments[1]) {
2730
const browser = await playwright.chromium.launchPersistentContext(
2831
path.resolve(__dirname, '../../userDataDir'),
2932
options
@@ -43,13 +46,26 @@ export async function getPage(options?: LaunchOptions) {
4346
}
4447

4548
const fileName = path.basename(request.url());
46-
const filePath = path.join(WA_DIR, fileName);
49+
const filePathDist = path.join(
50+
path.resolve(__dirname, '../../dist/'),
51+
fileName
52+
);
53+
54+
if (request.url().includes('dist') && fs.existsSync(filePathDist)) {
55+
return route.fulfill({
56+
status: 200,
57+
contentType: 'text/javascript; charset=UTF-8',
58+
body: fs.readFileSync(filePathDist, { encoding: 'utf8' }),
59+
});
60+
}
61+
62+
const filePathSource = path.join(WA_DIR, fileName);
4763

48-
if (fs.existsSync(filePath)) {
64+
if (fs.existsSync(filePathSource)) {
4965
return route.fulfill({
5066
status: 200,
5167
contentType: 'text/javascript; charset=UTF-8',
52-
body: fs.readFileSync(filePath, { encoding: 'utf8' }),
68+
body: fs.readFileSync(filePathSource, { encoding: 'utf8' }),
5369
});
5470
}
5571

@@ -76,7 +92,7 @@ export async function getPage(options?: LaunchOptions) {
7692

7793
page.on('domcontentloaded', async () => {
7894
await page.addScriptTag({
79-
path: path.resolve(__dirname, '../../dist/wppconnect-wa.js'),
95+
url: `${URL}dist/wppconnect-wa.js`,
8096
});
8197
});
8298

src/tools/launchLocal.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
import { getPage } from './browser';
1818

1919
async function start() {
20+
const args = process.argv.slice(2);
21+
2022
await getPage({
2123
headless: false,
22-
devtools: true,
24+
devtools: !args.some((m) => m.includes('--remote-debugging-port')),
25+
viewport: null,
26+
args,
2327
});
2428
}
2529
start();

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"removeComments": false,
1212
"resolveJsonModule": true,
1313
"skipLibCheck": true,
14+
"sourceMap": true,
1415
"strict": true,
1516
"target": "ES2017"
1617
},

0 commit comments

Comments
 (0)