-
Notifications
You must be signed in to change notification settings - Fork 713
iframes #778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
iframes #778
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
1889342
iframes wip
seanmcguire12 e01e974
works for act & observe
seanmcguire12 df54af9
move core logic into a11y/utils.ts
seanmcguire12 372c7da
iterative backend map building
seanmcguire12 d8104ef
dont use regex
seanmcguire12 6f2e406
assign ids
seanmcguire12 ee05623
works with extract
seanmcguire12 be5497b
revert example
seanmcguire12 f17bc5d
rm some useless comments
seanmcguire12 4f8f91a
fix targeted extract
seanmcguire12 44c1f9a
JSDoc
seanmcguire12 3d3eada
mv RichNode type
seanmcguire12 5aced2f
manage frame ordinals at the StagehandPage level
seanmcguire12 c45ffdf
add hn eval
seanmcguire12 5316ac6
more evals
seanmcguire12 fdd0644
parameterize iframe traversal
seanmcguire12 b630894
update evals with iframes: true
seanmcguire12 2770741
rm frame ID ordinal limit
seanmcguire12 e2d0c01
better errors and comment style
seanmcguire12 9207bec
rm unused error
seanmcguire12 a860c99
log warning if iframes are found when iframes: true is unset
seanmcguire12 d2c80e9
append iframes to observeResult when iframes: false
seanmcguire12 7aec392
changeset
seanmcguire12 06269e9
update docs
seanmcguire12 697e567
greptile comments
seanmcguire12 bc22241
make iframes experimental
seanmcguire12 1f80888
run evals with experimental: true
seanmcguire12 7430930
add ID_PATTERN const
seanmcguire12 a3b6b06
update package.json
seanmcguire12 a2d7e4d
fix nested same proc iframes
seanmcguire12 c17a209
nested iframes eval
seanmcguire12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@browserbasehq/stagehand-lib": minor | ||
--- | ||
|
||
iframe support |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { EvalFunction } from "@/types/evals"; | ||
|
||
export const iframe_form_filling: EvalFunction = async ({ | ||
debugUrl, | ||
sessionUrl, | ||
stagehand, | ||
logger, | ||
}) => { | ||
const page = stagehand.page; | ||
await page.goto( | ||
"https://browserbase.github.io/stagehand-eval-sites/sites/iframe-form-filling/", | ||
); | ||
|
||
await page.act({ | ||
action: "type 'nunya' into the 'first name' field", | ||
iframes: true, | ||
}); | ||
await page.act({ | ||
action: "type 'business' into the 'last name' field", | ||
iframes: true, | ||
}); | ||
await page.act({ | ||
action: "type '[email protected]' into the 'email' field", | ||
iframes: true, | ||
}); | ||
await page.act({ | ||
action: "click 'phone' as the preferred contact method", | ||
iframes: true, | ||
}); | ||
await page.act({ | ||
action: "type 'yooooooooooooooo' into the message box", | ||
iframes: true, | ||
}); | ||
|
||
const iframe = page.frameLocator("iframe"); | ||
|
||
const firstNameValue: string = await iframe | ||
.locator('input[placeholder="Jane"]') | ||
.inputValue(); | ||
|
||
const lastNameValue: string = await iframe | ||
.locator('input[placeholder="Doe"]') | ||
.inputValue(); | ||
|
||
const emailValue: string = await iframe | ||
.locator('input[placeholder="[email protected]"]') | ||
.inputValue(); | ||
|
||
const contactValue: boolean = await iframe | ||
.locator("xpath=/html/body/main/section[1]/form/fieldset/label[2]/input") | ||
.isChecked(); | ||
|
||
const messageValue: string = await iframe | ||
.locator('textarea[placeholder="Say hello…"]') | ||
.inputValue(); | ||
|
||
const passed: boolean = | ||
firstNameValue.toLowerCase().trim() === "nunya" && | ||
lastNameValue.toLowerCase().trim() === "business" && | ||
emailValue.toLowerCase() === "[email protected]" && | ||
messageValue.toLowerCase() === "yooooooooooooooo" && | ||
contactValue; | ||
|
||
return { | ||
_success: passed, | ||
logs: logger.getLogs(), | ||
debugUrl, | ||
sessionUrl, | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { EvalFunction } from "@/types/evals"; | ||
import { z } from "zod"; | ||
|
||
export const iframe_hn: EvalFunction = async ({ | ||
debugUrl, | ||
sessionUrl, | ||
stagehand, | ||
logger, | ||
}) => { | ||
const page = stagehand.page; | ||
await page.goto( | ||
"https://browserbase.github.io/stagehand-eval-sites/sites/iframe-hn/", | ||
); | ||
|
||
const result = await page.extract({ | ||
instruction: "extract the title of the first hackernews story", | ||
schema: z.object({ | ||
story_title: z.string(), | ||
}), | ||
iframes: true, | ||
}); | ||
|
||
await stagehand.close(); | ||
seanmcguire12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const title = result.story_title.toLowerCase(); | ||
const expectedTitleSubstring = "overengineered anchor links"; | ||
|
||
if (!title.includes(expectedTitleSubstring)) { | ||
logger.error({ | ||
message: `Extracted title: ${title} does not contain expected substring: ${expectedTitleSubstring}`, | ||
level: 0, | ||
}); | ||
return { | ||
_success: false, | ||
error: `Extracted title: ${title} does not contain expected substring: ${expectedTitleSubstring}`, | ||
logs: logger.getLogs(), | ||
debugUrl, | ||
sessionUrl, | ||
}; | ||
} | ||
|
||
return { | ||
_success: true, | ||
logs: logger.getLogs(), | ||
debugUrl, | ||
sessionUrl, | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { EvalFunction } from "@/types/evals"; | ||
|
||
export const iframe_same_proc: EvalFunction = async ({ | ||
debugUrl, | ||
sessionUrl, | ||
stagehand, | ||
logger, | ||
}) => { | ||
const page = stagehand.page; | ||
await page.goto( | ||
"https://browserbase.github.io/stagehand-eval-sites/sites/iframe-same-proc/", | ||
); | ||
|
||
await page.act({ | ||
action: "type 'stagehand' into the 'your name' field", | ||
iframes: true, | ||
}); | ||
|
||
// overly specific prompting is okay here. we are just trying to evaluate whether | ||
// we are properly traversing iframes | ||
await page.act({ | ||
action: | ||
"select 'Green' from the favorite colour dropdown. Ensure the word 'Green' is capitalized. Choose the selectOption playwright method.", | ||
iframes: true, | ||
}); | ||
|
||
const iframe = page.frameLocator("iframe"); | ||
|
||
const nameValue: string = await iframe | ||
.locator('input[placeholder="Alice"]') | ||
.inputValue(); | ||
|
||
const colorValue: string = await iframe.locator("select").inputValue(); | ||
|
||
const passed: boolean = | ||
nameValue.toLowerCase().trim() === "stagehand" && | ||
colorValue.toLowerCase().trim() === "green"; | ||
seanmcguire12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return { | ||
_success: passed, | ||
logs: logger.getLogs(), | ||
debugUrl, | ||
sessionUrl, | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { EvalFunction } from "@/types/evals"; | ||
import { FrameLocator } from "@playwright/test"; | ||
|
||
export const iframes_nested: EvalFunction = async ({ | ||
debugUrl, | ||
sessionUrl, | ||
stagehand, | ||
logger, | ||
}) => { | ||
const page = stagehand.page; | ||
try { | ||
await page.goto( | ||
"https://browserbase.github.io/stagehand-eval-sites/sites/nested-iframes/", | ||
); | ||
|
||
await page.act({ | ||
action: "type 'stagehand' into the 'username' field", | ||
iframes: true, | ||
}); | ||
|
||
const inner: FrameLocator = page | ||
.frameLocator("iframe.lvl1") // level 1 | ||
.frameLocator("iframe.lvl2") // level 2 | ||
.frameLocator("iframe.lvl3"); // level 3 – form lives here | ||
|
||
const usernameText = await inner | ||
.locator('input[name="username"]') | ||
.inputValue(); | ||
|
||
const passed: boolean = usernameText.toLowerCase().trim() === "stagehand"; | ||
|
||
return { | ||
_success: passed, | ||
logs: logger.getLogs(), | ||
debugUrl, | ||
sessionUrl, | ||
}; | ||
} catch (error) { | ||
return { | ||
_success: false, | ||
logs: logger.getLogs(), | ||
debugUrl, | ||
sessionUrl, | ||
error, | ||
}; | ||
} finally { | ||
await stagehand.close(); | ||
} | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.