* Sets the cache behavior for network requests. * * @param {string} behavior - The cache behavior ("default" or "bypass") * @param {Array } [contexts] - Optional array of browsing context IDs * @returns {Promise } A promise that resolves when the cache behavior is set * @t
(behavior, contexts = null)
| 369 | * @throws {Error} If behavior is invalid or context IDs are invalid |
| 370 | */ |
| 371 | async setCacheBehavior(behavior, contexts = null) { |
| 372 | if (!Object.values(CacheBehavior).includes(behavior)) { |
| 373 | throw new Error(`Cache behavior must be either "${CacheBehavior.DEFAULT}" or "${CacheBehavior.BYPASS}"`) |
| 374 | } |
| 375 | |
| 376 | const command = { |
| 377 | method: 'network.setCacheBehavior', |
| 378 | params: { |
| 379 | cacheBehavior: behavior, |
| 380 | }, |
| 381 | } |
| 382 | |
| 383 | if (contexts !== null) { |
| 384 | if ( |
| 385 | !Array.isArray(contexts) || |
| 386 | contexts.length === 0 || |
| 387 | contexts.some((c) => typeof c !== 'string' || c.trim() === '') |
| 388 | ) { |
| 389 | throw new Error('Contexts must be an array of non-empty strings') |
| 390 | } |
| 391 | command.params.contexts = contexts |
| 392 | } |
| 393 | |
| 394 | await this.bidi.send(command) |
| 395 | } |
| 396 | |
| 397 | /** |
| 398 | * Unsubscribes from network events for all browsing contexts. |
no test coverage detected