@@ -16,38 +16,38 @@ To get started with Stagehand, check out this [example guide](/browser-rendering
1616![ Stagehand video] ( ~/assets/images/browser-rendering//stagehand.gif )
1717
1818``` ts title="Stagehand example"
19- const stagehand = new Stagehand ({
20- env: " LOCAL" ,
21- localBrowserLaunchOptions: { cdpUrl: endpointURLString (env .BROWSER ) },
22- llmClient: new WorkersAIClient (env .AI ),
23- verbose: 1 ,
24- });
19+ const stagehand = new Stagehand ({
20+ env: " LOCAL" ,
21+ localBrowserLaunchOptions: { cdpUrl: endpointURLString (env .BROWSER ) },
22+ llmClient: new WorkersAIClient (env .AI ),
23+ verbose: 1 ,
24+ });
2525
26- await stagehand .init ();
27- const page = stagehand .page ;
26+ await stagehand .init ();
27+ const page = stagehand .page ;
2828
29- await page .goto (' https://demo.playwright.dev/movies' );
29+ await page .goto (' https://demo.playwright.dev/movies' );
3030
31- // if search is a multi-step action, stagehand will return an array of actions it needs to act on
32- const actions = await page .observe (' Search for "Furiosa"' );
33- for (const action of actions )
34- await page .act (action );
31+ // if search is a multi-step action, stagehand will return an array of actions it needs to act on
32+ const actions = await page .observe (' Search for "Furiosa"' );
33+ for (const action of actions )
34+ await page .act (action );
3535
36- await page .act (' Click the search result' );
36+ await page .act (' Click the search result' );
3737
38- // normal playwright functions work as expected
38+ // normal playwright functions work as expected
3939 await page .waitForSelector (' .info-wrapper .cast' );
4040
41- let movieInfo = await page .extract ({
42- instruction: ' Extract movie information' ,
43- schema: z .object ({
44- title: z .string (),
45- year: z .number (),
46- rating: z .number (),
47- genres: z .array (z .string ()),
48- duration: z .number ().describe (" Duration in minutes" ),
49- }),
50- });
51-
52- await stagehand .close ();
41+ let movieInfo = await page .extract ({
42+ instruction: ' Extract movie information' ,
43+ schema: z .object ({
44+ title: z .string (),
45+ year: z .number (),
46+ rating: z .number (),
47+ genres: z .array (z .string ()),
48+ duration: z .number ().describe (" Duration in minutes" ),
49+ }),
50+ });
51+
52+ await stagehand .close ();
5353```
0 commit comments