Skip to content

Commit

Permalink
Bump Version to 1.1.2 (#178)
Browse files Browse the repository at this point in the history
* Add init scripts to the context, not just the page

* 1.1.2
  • Loading branch information
pkiv authored Nov 11, 2024
1 parent d7d4f59 commit 4e52dd8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
57 changes: 48 additions & 9 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ export class Stagehand {
llmProvider || new LLMProvider(this.logger, this.enableCaching);
this.env = env;
this.observations = {};
this.apiKey = apiKey || process.env.BROWSERBASE_API_KEY;
this.projectId = projectId || process.env.BROWSERBASE_PROJECT_ID;
this.apiKey = apiKey ?? process.env.BROWSERBASE_API_KEY;
this.projectId = projectId ?? process.env.BROWSERBASE_PROJECT_ID;
this.verbose = verbose ?? 0;
this.debugDom = debugDom ?? false;
this.defaultModelName = "gpt-4o";
Expand Down Expand Up @@ -339,6 +339,9 @@ export class Stagehand {
});
this.context = context;
this.page = context.pages()[0];
// Redundant but needed for users who are re-connecting to a previously-created session
await this.page.waitForLoadState("domcontentloaded");
await this._waitForSettledDom();
this.defaultModelName = modelName;
this.domSettleTimeoutMs = domSettleTimeoutMs ?? this.domSettleTimeoutMs;

Expand All @@ -358,16 +361,36 @@ export class Stagehand {

// This can be greatly improved, but the tldr is we put our built web scripts in dist, which should always
// be one level above our running directly across evals, example, and as a package
await this.page.addInitScript({
await this.context.addInitScript({
path: path.join(__dirname, "..", "dist", "dom", "build", "xpathUtils.js"),
content: fs.readFileSync(
path.join(__dirname, "..", "dist", "dom", "build", "xpathUtils.js"),
"utf8",
),
});

await this.context.addInitScript({
path: path.join(__dirname, "..", "dist", "dom", "build", "process.js"),
content: fs.readFileSync(
path.join(__dirname, "..", "dist", "dom", "build", "process.js"),
"utf8",
),
});

await this.page.addInitScript({
await this.context.addInitScript({
path: path.join(__dirname, "..", "dist", "dom", "build", "utils.js"),
content: fs.readFileSync(
path.join(__dirname, "..", "dist", "dom", "build", "utils.js"),
"utf8",
),
});

await this.page.addInitScript({
await this.context.addInitScript({
path: path.join(__dirname, "..", "dist", "dom", "build", "debug.js"),
content: fs.readFileSync(
path.join(__dirname, "..", "dist", "dom", "build", "debug.js"),
"utf8",
),
});

return { debugUrl, sessionUrl };
Expand Down Expand Up @@ -395,20 +418,36 @@ export class Stagehand {
}

// Add initialization scripts
await this.page.addInitScript({
await this.context.addInitScript({
path: path.join(__dirname, "..", "dist", "dom", "build", "xpathUtils.js"),
content: fs.readFileSync(
path.join(__dirname, "..", "dist", "dom", "build", "xpathUtils.js"),
"utf8",
),
});

await this.page.addInitScript({
await this.context.addInitScript({
path: path.join(__dirname, "..", "dist", "dom", "build", "process.js"),
content: fs.readFileSync(
path.join(__dirname, "..", "dist", "dom", "build", "process.js"),
"utf8",
),
});

await this.page.addInitScript({
await this.context.addInitScript({
path: path.join(__dirname, "..", "dist", "dom", "build", "utils.js"),
content: fs.readFileSync(
path.join(__dirname, "..", "dist", "dom", "build", "utils.js"),
"utf8",
),
});

await this.page.addInitScript({
await this.context.addInitScript({
path: path.join(__dirname, "..", "dist", "dom", "build", "debug.js"),
content: fs.readFileSync(
path.join(__dirname, "..", "dist", "dom", "build", "debug.js"),
"utf8",
),
});

return { context: this.context };
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@browserbasehq/stagehand",
"version": "1.1.1",
"version": "1.1.2",
"description": "An AI web browsing framework focused on simplicity and extensibility.",
"main": "./dist/index.js",
"module": "./dist/index.js",
Expand Down

0 comments on commit 4e52dd8

Please sign in to comment.