Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #125 from hdresearch/ty/emails-as-text
Browse files Browse the repository at this point in the history
Ty/emails as text
  • Loading branch information
matildepark authored Aug 27, 2024
2 parents 80ef82c + b3ae9e0 commit 2c485b2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ export class Browser {
disableMemory?: boolean;
}): Promise<Page> {
const basePage = await this.browser.newPage();

await basePage.setRequestInterception(true);
basePage.on("request", (request) => {
if (request.url().startsWith("mailto:")) {
request.abort();
} else {
request.continue();
}
});

if (opts?.device) {
await basePage.emulate(opts.device);
}
Expand Down
7 changes: 7 additions & 0 deletions src/browser/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { fetchMemorySequence, remember } from "../collectiveMemory/remember";
import { ModelResponseType } from "../types";
import { DEFAULT_STATE_ACTION_PAIRS } from "../collectiveMemory/examples";
import { Memory } from "../types/memory.types";
import { isEmail } from "../utils/ariaUtils";

/**
* Represents a web page and provides methods to interact with it.
Expand Down Expand Up @@ -283,6 +284,12 @@ export class Page {
}
const index = this.idMapping.size;
const e: AccessibilityTree = [index, node.role, node.name!];

if (e[1] === "link") {
if (isEmail(e[2])) {
e[1] = "StaticText(email)";
}
}
this.idMapping.set(index, e);
let children = [] as AccessibilityTree[];
if (node.children) {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/ariaUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function isEmail(text: string): boolean {
const pattern: RegExp = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
return pattern.test(text);
}

0 comments on commit 2c485b2

Please sign in to comment.