fix: return full content on first snapshot call instead of message
This commit is contained in:
@@ -65,40 +65,26 @@ export async function getCleanHTML(options: GetCleanHTMLOptions): Promise<string
|
||||
// Sanitize to remove unpaired surrogates that break JSON encoding
|
||||
let htmlStr = cleanedHtml.toWellFormed?.() ?? cleanedHtml
|
||||
|
||||
// Handle diffing
|
||||
if (showDiffSinceLastCall) {
|
||||
let pageSnapshots = lastHtmlSnapshots.get(page)
|
||||
if (!pageSnapshots) {
|
||||
pageSnapshots = new Map()
|
||||
lastHtmlSnapshots.set(page, pageSnapshots)
|
||||
}
|
||||
|
||||
const snapshotKey = getSnapshotKey(locator)
|
||||
const previousSnapshot = pageSnapshots.get(snapshotKey)
|
||||
|
||||
if (!previousSnapshot) {
|
||||
pageSnapshots.set(snapshotKey, htmlStr)
|
||||
return 'No previous snapshot available. This is the first call for this locator. Full snapshot stored for next diff.'
|
||||
}
|
||||
|
||||
const diffResult = createSmartDiff({
|
||||
oldContent: previousSnapshot,
|
||||
newContent: htmlStr,
|
||||
label: 'html',
|
||||
})
|
||||
|
||||
pageSnapshots.set(snapshotKey, htmlStr)
|
||||
|
||||
return diffResult.content
|
||||
}
|
||||
|
||||
// Store snapshot for future diffs
|
||||
// Store snapshot and handle diffing
|
||||
let pageSnapshots = lastHtmlSnapshots.get(page)
|
||||
if (!pageSnapshots) {
|
||||
pageSnapshots = new Map()
|
||||
lastHtmlSnapshots.set(page, pageSnapshots)
|
||||
}
|
||||
pageSnapshots.set(getSnapshotKey(locator), htmlStr)
|
||||
|
||||
const snapshotKey = getSnapshotKey(locator)
|
||||
const previousSnapshot = pageSnapshots.get(snapshotKey)
|
||||
pageSnapshots.set(snapshotKey, htmlStr)
|
||||
|
||||
// Return diff if we have a previous snapshot and diff mode is enabled
|
||||
if (showDiffSinceLastCall && previousSnapshot) {
|
||||
const diffResult = createSmartDiff({
|
||||
oldContent: previousSnapshot,
|
||||
newContent: htmlStr,
|
||||
label: 'html',
|
||||
})
|
||||
return diffResult.content
|
||||
}
|
||||
|
||||
// Handle search
|
||||
if (search) {
|
||||
|
||||
@@ -472,23 +472,19 @@ export class PlaywrightExecutor {
|
||||
}
|
||||
this.lastRefToLocator.set(targetPage, refToLocator)
|
||||
|
||||
if (showDiffSinceLastCall) {
|
||||
const previousSnapshot = this.lastSnapshots.get(targetPage)
|
||||
if (!previousSnapshot) {
|
||||
this.lastSnapshots.set(targetPage, snapshotStr)
|
||||
return 'No previous snapshot available. This is the first call for this page. Full snapshot stored for next diff.'
|
||||
}
|
||||
const previousSnapshot = this.lastSnapshots.get(targetPage)
|
||||
this.lastSnapshots.set(targetPage, snapshotStr)
|
||||
|
||||
// Return diff if we have a previous snapshot and diff mode is enabled
|
||||
if (showDiffSinceLastCall && previousSnapshot) {
|
||||
const diffResult = createSmartDiff({
|
||||
oldContent: previousSnapshot,
|
||||
newContent: snapshotStr,
|
||||
label: 'snapshot',
|
||||
})
|
||||
this.lastSnapshots.set(targetPage, snapshotStr)
|
||||
return diffResult.content
|
||||
}
|
||||
|
||||
this.lastSnapshots.set(targetPage, snapshotStr)
|
||||
|
||||
if (!search) {
|
||||
return `${snapshotStr}\n\nuse refToLocator({ ref: 'e3' }) to get locators for ref strings.`
|
||||
}
|
||||
|
||||
@@ -168,29 +168,20 @@ export async function getPageMarkdown(options: GetPageMarkdownOptions): Promise<
|
||||
// Sanitize to remove unpaired surrogates that break JSON encoding
|
||||
markdown = markdown.toWellFormed?.() ?? markdown
|
||||
|
||||
// Handle diffing
|
||||
if (showDiffSinceLastCall) {
|
||||
const previousSnapshot = lastMarkdownSnapshots.get(page)
|
||||
|
||||
if (!previousSnapshot) {
|
||||
lastMarkdownSnapshots.set(page, markdown)
|
||||
return 'No previous snapshot available. This is the first call. Full snapshot stored for next diff.'
|
||||
}
|
||||
// Store snapshot and handle diffing
|
||||
const previousSnapshot = lastMarkdownSnapshots.get(page)
|
||||
lastMarkdownSnapshots.set(page, markdown)
|
||||
|
||||
// Return diff if we have a previous snapshot and diff mode is enabled
|
||||
if (showDiffSinceLastCall && previousSnapshot) {
|
||||
const diffResult = createSmartDiff({
|
||||
oldContent: previousSnapshot,
|
||||
newContent: markdown,
|
||||
label: 'content',
|
||||
})
|
||||
|
||||
lastMarkdownSnapshots.set(page, markdown)
|
||||
|
||||
return diffResult.content
|
||||
}
|
||||
|
||||
// Store snapshot for future diffs
|
||||
lastMarkdownSnapshots.set(page, markdown)
|
||||
|
||||
// Handle search
|
||||
if (search) {
|
||||
const contentLines = markdown.split('\n')
|
||||
|
||||
@@ -245,7 +245,7 @@ await accessibilitySnapshot({ page, search?, showDiffSinceLastCall? })
|
||||
- `search` - string/regex to filter results (returns first 10 matching lines)
|
||||
- `showDiffSinceLastCall` - returns diff since last snapshot (default: `true`). Pass `false` to get full snapshot.
|
||||
|
||||
Snapshots automatically return diffs after the first call. The diff is returned only when it's shorter than the full content.
|
||||
Snapshots return full content on first call, then diffs on subsequent calls. Diff is only returned when shorter than full content.
|
||||
|
||||
Example output:
|
||||
|
||||
@@ -494,7 +494,7 @@ The function cleans HTML for compact, readable output:
|
||||
- All `data-*` test attributes
|
||||
- Frequently used test IDs and special attributes (e.g., `testid`, `qa`, `e2e`, `vimium-label`)
|
||||
|
||||
Snapshots automatically return diffs after the first call. The diff is returned only when it's shorter than the full content.
|
||||
Snapshots return full content on first call, then diffs on subsequent calls. Diff is only returned when shorter than full content.
|
||||
|
||||
**getPageMarkdown** - extract main page content as plain text using Mozilla Readability (same algorithm as Firefox Reader View). Strips navigation, ads, sidebars, and other clutter. Returns formatted text with title, author, and content:
|
||||
|
||||
@@ -521,7 +521,7 @@ The main article content as plain text, with paragraphs preserved...
|
||||
- `search` - string/regex to filter content (returns first 10 matching lines with 5 lines context)
|
||||
- `showDiffSinceLastCall` - returns diff since last call (default: `true`). Pass `false` to get full content.
|
||||
|
||||
Snapshots automatically return diffs after the first call. The diff is returned only when it's shorter than the full content.
|
||||
Snapshots return full content on first call, then diffs on subsequent calls. Diff is only returned when shorter than full content.
|
||||
|
||||
**Use cases:**
|
||||
- Extract article text for LLM processing without HTML noise
|
||||
|
||||
Reference in New Issue
Block a user