Skip to content

Commit

Permalink
Feat/devtools option (#33)
Browse files Browse the repository at this point in the history
* feat: add devtools flag

* chore: adding changeset

* chore: update changeset
  • Loading branch information
heyMP authored Aug 1, 2024
1 parent 3174092 commit db0f2af
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/dull-candles-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@heymp/scratchpad": minor
---

Open devtools automatically with cli flag. Use the `--devtools` flag
to enable the devtools in the browser.
3 changes: 2 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const program = new Command();
program
.argument('<file>', 'file to execute in the browser.')
.option('--headless [boolean]', 'specify running the browser in headless mode.')
.option('--devtools [boolean]', 'open browser devtools automatically.')
.option('--url [string]', 'specify a specific url to execute the code in.')
.version(pkg.version)
program.parse(process.argv);
Expand All @@ -28,6 +29,7 @@ class Processor extends EventTarget {
super();
this.url = opts['url'];
this.headless = opts['headless'];
this.devtools = opts['devtools'];
this._func = '';
this.watcher();
browser(this);
Expand All @@ -54,7 +56,6 @@ class Processor extends EventTarget {
}

async build() {
console.log('build')
try {
if (file.endsWith('.ts')) {
const { outputFiles: [stdout]} = await esbuild.build({
Expand Down
4 changes: 2 additions & 2 deletions src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function nodelog(value) {
export async function browser(processor) {
// Launch the browser
const browser = await playwright['chromium'].launch({
headless: processor.headless,
devtools: true
headless: !!processor.headless,
devtools: !!processor.devtools
});
const context = await browser.newContext();
const page = await context.newPage();
Expand Down

0 comments on commit db0f2af

Please sign in to comment.