Skip to content

Commit

Permalink
Merge pull request #627 from marp-team/stable-preview-window-detector
Browse files Browse the repository at this point in the history
Make the preview option stable against occasional invalid URL errors
  • Loading branch information
yhatt authored Jan 14, 2025
2 parents a533875 + 471fbe8 commit 19f8166
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Make the preview option stable against occasional invalid URL errors ([#627](https://github.com/marp-team/marp-cli/pull/627))

## v4.0.4 - 2024-12-25

### Added
Expand Down
16 changes: 9 additions & 7 deletions src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,17 @@ export class Preview extends (EventEmitter as new () => TypedEmitter<Preview.Eve
const idMatcher = (target: Target) => {
debugPreview('Activated the window finder for %s.', id)

const url = new URL(target.url())
if (target.type() === 'page') {
const url = new URL(target.url())

if (url.searchParams.get('__marp_cli_id') === id) {
debugPreview('Found a target window with id: %s', id)
pptr.off('targetcreated', idMatcher)
if (url.searchParams.get('__marp_cli_id') === id) {
debugPreview('Found a target window with id: %s', id)
pptr.off('targetcreated', idMatcher)

void (async () => {
res((await target.page()) ?? (await target.asPage()))
})()
void (async () => {
res((await target.page()) ?? (await target.asPage()))
})()
}
}
}

Expand Down

0 comments on commit 19f8166

Please sign in to comment.