Skip to content

Commit

Permalink
Merge pull request #357 from ulixee/fix(agent)--support-callbacks-in-…
Browse files Browse the repository at this point in the history
…chrome-internal-urls

fix(agent): support callbacks in chrome internal urls
  • Loading branch information
blakebyrnes authored Feb 5, 2025
2 parents 6b46e57 + 5b0c41e commit 933e5e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions agent/main/lib/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,16 @@ export class Console extends TypedEventEmitter<IConsoleEvents> {
function injectedScript(): void {
const clientId = Math.random().toString().slice(2, 12);

const url = `http://hero.localhost/?secretKey=${this.secretKey}&action=registerConsoleClientId&clientId=${clientId}`;

// This will signal to network manager we are trying to make websocket connection
// This is needed later to map clientId to frameId

const scheme = location.href.startsWith('chrome://') ? 'data' : 'http'
const url = `${scheme}://hero.localhost/?secretKey=${this.secretKey}&action=registerConsoleClientId&clientId=${clientId}`;
if (scheme === 'data') {
// eslint-disable-next-line no-console
console.info('Using fetch with data:// scheme, http:// not supported inside chrome:// urls, ignore fetch errors including data:// scheme')
}

void fetch(url, { mode: 'no-cors' }).catch(() => undefined);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
1 change: 1 addition & 0 deletions agent/main/lib/NetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default class NetworkManager extends TypedEventEmitter<IBrowserNetworkEve

const patternsToIntercepts: Fetch.RequestPattern[] = [
{ urlPattern: 'http://hero.localhost/*' },
{ urlPattern: 'data://hero.localhost/*' },
];
if (this.proxyConnectionOptions?.password) {
// Pattern needs to match website url (not proxy url), so wildcard is only option we really have here
Expand Down

0 comments on commit 933e5e7

Please sign in to comment.