-
Notifications
You must be signed in to change notification settings - Fork 964
add support for shadow doms (open & closed mode) #954
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
Open
seanmcguire12
wants to merge
12
commits into
main
Choose a base branch
from
sean/stg-659-add-support-for-shadow-doms
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cf777ae
generate correct IDs for shadow DOM elements
seanmcguire12 624fadc
add custom locator engine & shadow dom traversal logic
seanmcguire12 98c17ee
rm getShadowRootHandle
seanmcguire12 5ffcfb7
rm ensureStagehandScript
seanmcguire12 7a84581
add custom locator engine & shadow dom traversal logic
seanmcguire12 aa7ae85
rm getShadowRootHandle
seanmcguire12 494476f
make sure __stagehand__ is not defined before we attempt to define it
seanmcguire12 f34b8ea
add evals
seanmcguire12 fabd26b
add support for iframes inside of shadow roots
seanmcguire12 7ad773e
put shadow dom support behind experimental flag
seanmcguire12 be7f776
changeset
seanmcguire12 fd7338a
update evals with success: false on failure
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": patch | ||
--- | ||
|
||
add support for shadow DOMs (open & closed mode) when experimental: true |
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,54 @@ | ||
import { EvalFunction } from "@/types/evals"; | ||
|
||
export const csr_in_oopif: EvalFunction = async ({ | ||
debugUrl, | ||
sessionUrl, | ||
stagehand, | ||
logger, | ||
}) => { | ||
// this eval is designed to test whether stagehand can successfully | ||
// click inside an CSR (closed mode shadow) root that is inside an | ||
// OOPIF (out of process iframe) | ||
|
||
const page = stagehand.page; | ||
try { | ||
await page.goto( | ||
"https://browserbase.github.io/stagehand-eval-sites/sites/closed-shadow-root-in-oopif/", | ||
); | ||
await page.act({ action: "click the button", iframes: true }); | ||
|
||
const extraction = await page.extract({ | ||
instruction: "extract the entire page text", | ||
iframes: true, | ||
}); | ||
|
||
const pageText = extraction.extraction; | ||
|
||
if (pageText.includes("button successfully clicked")) { | ||
return { | ||
_success: true, | ||
message: `successfully clicked the button`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} | ||
return { | ||
_success: false, | ||
message: `unable to click on the button`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} catch (error) { | ||
return { | ||
_success: false, | ||
message: `error: ${error.message}`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} finally { | ||
await stagehand.close(); | ||
} | ||
}; |
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,54 @@ | ||
import { EvalFunction } from "@/types/evals"; | ||
|
||
export const csr_in_spif: EvalFunction = async ({ | ||
debugUrl, | ||
sessionUrl, | ||
stagehand, | ||
logger, | ||
}) => { | ||
// this eval is designed to test whether stagehand can successfully | ||
// click inside an CSR (closed mode shadow) root that is inside an | ||
// SPIF (same process iframe) | ||
|
||
const page = stagehand.page; | ||
try { | ||
await page.goto( | ||
"https://browserbase.github.io/stagehand-eval-sites/sites/closed-shadow-dom-in-spif/", | ||
); | ||
await page.act({ action: "click the button", iframes: true }); | ||
|
||
const extraction = await page.extract({ | ||
instruction: "extract the entire page text", | ||
iframes: true, | ||
}); | ||
|
||
const pageText = extraction.extraction; | ||
|
||
if (pageText.includes("button successfully clicked")) { | ||
return { | ||
_success: true, | ||
message: `successfully clicked the button`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} | ||
return { | ||
_success: false, | ||
message: `unable to click on the button`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} catch (error) { | ||
return { | ||
_success: false, | ||
message: `error: ${error.message}`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} finally { | ||
await stagehand.close(); | ||
} | ||
}; |
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,57 @@ | ||
import { EvalFunction } from "@/types/evals"; | ||
|
||
export const oopif_in_csr: EvalFunction = async ({ | ||
debugUrl, | ||
sessionUrl, | ||
stagehand, | ||
logger, | ||
}) => { | ||
// this eval is designed to test whether stagehand can successfully | ||
// fill a form inside a OOPIF (out of process iframe) that is inside an | ||
// CSR (closed mode shadow) root | ||
|
||
const page = stagehand.page; | ||
try { | ||
await page.goto( | ||
"https://browserbase.github.io/stagehand-eval-sites/sites/oopif-in-open-shadow-dom/", | ||
); | ||
await page.act({ | ||
action: "fill 'nunya' into the first name field", | ||
iframes: true, | ||
}); | ||
|
||
const extraction = await page.extract({ | ||
instruction: "extract the entire page text", | ||
iframes: true, | ||
}); | ||
|
||
const pageText = extraction.extraction; | ||
|
||
if (pageText.includes("nunya")) { | ||
return { | ||
_success: true, | ||
message: `successfully filled the form`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} | ||
return { | ||
_success: false, | ||
message: `unable to fill the form`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} catch (error) { | ||
return { | ||
_success: false, | ||
message: `error: ${error.message}`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} finally { | ||
await stagehand.close(); | ||
} | ||
}; |
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,57 @@ | ||
import { EvalFunction } from "@/types/evals"; | ||
|
||
export const oopif_in_osr: EvalFunction = async ({ | ||
debugUrl, | ||
sessionUrl, | ||
stagehand, | ||
logger, | ||
}) => { | ||
// this eval is designed to test whether stagehand can successfully | ||
// fill a form inside a OOPIF (out of process iframe) that is inside an | ||
// OSR (open mode shadow) root | ||
|
||
const page = stagehand.page; | ||
try { | ||
await page.goto( | ||
"https://browserbase.github.io/stagehand-eval-sites/sites/oopif-in-open-shadow-dom/", | ||
); | ||
await page.act({ | ||
action: "fill 'nunya' into the first name field", | ||
iframes: true, | ||
}); | ||
|
||
const extraction = await page.extract({ | ||
instruction: "extract the entire page text", | ||
iframes: true, | ||
}); | ||
|
||
const pageText = extraction.extraction; | ||
|
||
if (pageText.includes("nunya")) { | ||
return { | ||
_success: true, | ||
message: `successfully filled the form`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} | ||
return { | ||
_success: false, | ||
message: `unable to fill the form`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} catch (error) { | ||
return { | ||
_success: false, | ||
message: `error: ${error.message}`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} finally { | ||
await stagehand.close(); | ||
} | ||
}; |
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,54 @@ | ||
import { EvalFunction } from "@/types/evals"; | ||
|
||
export const osr_in_oopif: EvalFunction = async ({ | ||
debugUrl, | ||
sessionUrl, | ||
stagehand, | ||
logger, | ||
}) => { | ||
// this eval is designed to test whether stagehand can successfully | ||
// click inside an OSR (open mode shadow) root that is inside an | ||
// OOPIF (out of process iframe) | ||
|
||
const page = stagehand.page; | ||
try { | ||
await page.goto( | ||
"https://browserbase.github.io/stagehand-eval-sites/sites/open-shadow-root-in-oopif/", | ||
); | ||
await page.act({ action: "click the button", iframes: true }); | ||
|
||
const extraction = await page.extract({ | ||
instruction: "extract the entire page text", | ||
iframes: true, | ||
}); | ||
|
||
const pageText = extraction.extraction; | ||
|
||
if (pageText.includes("button successfully clicked")) { | ||
return { | ||
_success: true, | ||
message: `successfully clicked the button`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} | ||
seanmcguire12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return { | ||
_success: false, | ||
message: `unable to click on the button`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} catch (error) { | ||
return { | ||
_success: false, | ||
message: `error: ${error.message}`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} finally { | ||
await stagehand.close(); | ||
} | ||
}; |
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,54 @@ | ||
import { EvalFunction } from "@/types/evals"; | ||
|
||
export const osr_in_spif: EvalFunction = async ({ | ||
debugUrl, | ||
sessionUrl, | ||
stagehand, | ||
logger, | ||
}) => { | ||
// this eval is designed to test whether stagehand can successfully | ||
// click inside an OSR (open mode shadow) root that is inside an | ||
// SPIF (same process iframe) | ||
|
||
const page = stagehand.page; | ||
try { | ||
await page.goto( | ||
"https://browserbase.github.io/stagehand-eval-sites/sites/open-shadow-root-in-spif/", | ||
); | ||
await page.act({ action: "click the button", iframes: true }); | ||
|
||
const extraction = await page.extract({ | ||
instruction: "extract the entire page text", | ||
iframes: true, | ||
}); | ||
|
||
const pageText = extraction.extraction; | ||
|
||
if (pageText.includes("button successfully clicked")) { | ||
return { | ||
_success: true, | ||
message: `successfully clicked the button`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} | ||
return { | ||
_success: false, | ||
message: `unable to click on the button`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} catch (error) { | ||
return { | ||
_success: false, | ||
message: `error: ${error.message}`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
seanmcguire12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} 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.