Skip to content

Commit

Permalink
more test
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore committed Mar 31, 2024
1 parent 942d47a commit 411a107
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions lib/firefox/firefoxBidi.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,33 @@ export class FirefoxBidi {
}

async blockUrls(blockers) {
// bin/browsertime.js --block upload.wikimedia.org https://en.wikipedia.org/wiki/Barack_Obama -n 1 -b firefox
const patterns = [];
const block = toArray(blockers);
for (let b of block) {
// Block a specific URL
if (b.startsWith('http')) {
patterns.push({ type: 'string', pattern: b });
} else {
// Block by domain
patterns.push({ type: 'pattern', hostname: b });
}
}

const bidi = new Bidi(this.driver, this.options.browser);

console.log(blockers);
const command = {
method: 'network.addIntercept',
params: {
phases: ['beforeRequestSent'],
// urlPatters: [{ type: 'pattern', hostname: blockers }]
urlPatterns: [{ type: 'string', pattern: blockers }]
urlPatterns: patterns
}
};
const result = await bidi.send(command);
console.log(result);
if (result.type != 'success') {
log.error(result);
}

await bidi.subscribe('network.beforeRequestSent');

await bidi.onMessage(async function (event) {
Expand All @@ -58,16 +71,10 @@ export class FirefoxBidi {
request: parsedEvent.params.request.request
}
};
const a = await bidi.send(fail);
} else if (parsedEvent.method === 'network.beforeRequestSent') {
const continueReq = {
method: 'network.continueRequest',
params: {
request: parsedEvent.params.request.request
}
};
const a = await bidi.send(continueReq);
// console.log(a);
const result = await bidi.send(fail);
if (result.type != 'success') {
log.error(result);
}
}
});
}
Expand Down

0 comments on commit 411a107

Please sign in to comment.