Skip to content

Commit d7901d7

Browse files
Fix frame-filter parsing for host-port urls
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent a6cffe8 commit d7901d7

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

‎currentState.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ HyperAgent exposes a TypeScript SDK for browser automation with three primary pa
142142
- Added an additional open-tab fallback path: when the tab array becomes unreadable (e.g. trapped `length`), prompt assembly now still emits the current tab line instead of a blank/no-tabs summary.
143143
- Added constructor regression coverage for trap-prone `llm` config getters, ensuring fallback failure paths stay deterministic and readable.
144144
- Hardened CDP frame-filter URL normalization to support protocol-relative and scheme-less frame URLs while avoiding path-only false positives in host-based ad-domain detection.
145+
- Refined CDP frame-filter URL normalization to correctly handle scheme-less `host:port` URLs (without misclassifying them as custom schemes), preserving ad-domain detection coverage in those cases.
145146
- Hardened prompt base-message materialization with trap-safe array reads so malformed/trap-prone seed message arrays no longer crash message assembly and readable entries are preserved.
146147
- Hardened constructor custom-action ingestion with trap-safe array reads so unreadable custom-action entries are skipped while valid entries continue to register.
147148
- Expanded top-level package exports for key workflow/config types at `@hyperbrowser/agent`.

‎src/cdp/frame-filters.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ describe("isAdOrTrackingFrame", () => {
4242
).toBe(true);
4343
});
4444

45+
it("filters known ad domains with host:port urls missing explicit protocol", () => {
46+
expect(
47+
isAdOrTrackingFrame({
48+
url: "securepubads.g.doubleclick.net:443/pagead/ads",
49+
})
50+
).toBe(true);
51+
});
52+
4553
it("filters obvious pixel-style tracking frames", () => {
4654
expect(
4755
isAdOrTrackingFrame({

‎src/cdp/frame-filters.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,17 @@ const TRACKING_PARAMS = [
101101

102102
const MIN_FILTER_SCORE = 2;
103103

104-
const HAS_PROTOCOL_PATTERN = /^[a-z][a-z0-9+\-.]*:/i;
104+
const HAS_SCHEME_WITH_SLASHES_PATTERN = /^[a-z][a-z0-9+\-.]*:\/\//i;
105+
const SPECIAL_SCHEME_PREFIXES = [
106+
"about:",
107+
"data:",
108+
"blob:",
109+
"file:",
110+
"javascript:",
111+
"mailto:",
112+
"chrome:",
113+
"devtools:",
114+
];
105115

106116
function normalizeUrlForParsing(value: string): string {
107117
const trimmed = value.trim();
@@ -111,7 +121,12 @@ function normalizeUrlForParsing(value: string): string {
111121
if (trimmed.startsWith("//")) {
112122
return `https:${trimmed}`;
113123
}
114-
if (HAS_PROTOCOL_PATTERN.test(trimmed)) {
124+
if (
125+
HAS_SCHEME_WITH_SLASHES_PATTERN.test(trimmed) ||
126+
SPECIAL_SCHEME_PREFIXES.some((prefix) =>
127+
trimmed.toLowerCase().startsWith(prefix)
128+
)
129+
) {
115130
return trimmed;
116131
}
117132
if (trimmed.startsWith("/")) {

0 commit comments

Comments
 (0)