/** * Copyright 2017 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { EventEmitter } from '../common/EventEmitter.js'; import { debugError } from '../common/util.js'; import { asyncDisposeSymbol, disposeSymbol } from '../util/disposable.js'; /** * {@link BrowserContext} represents individual sessions within a * {@link Browser | browser}. * * When a {@link Browser | browser} is launched, it has a single * {@link BrowserContext | browser context} by default. Others can be created * using {@link Browser.createIncognitoBrowserContext}. * * {@link BrowserContext} {@link EventEmitter | emits} various events which are * documented in the {@link BrowserContextEvent} enum. * * If a {@link Page | page} opens another {@link Page | page}, e.g. using * `window.open`, the popup will belong to the parent {@link Page.browserContext * | page's browser context}. * * @example Creating an incognito {@link BrowserContext | browser context}: * * ```ts * // Create a new incognito browser context * const context = await browser.createIncognitoBrowserContext(); * // Create a new page inside context. * const page = await context.newPage(); * // ... do stuff with page ... * await page.goto('https://example.com'); * // Dispose context once it's no longer needed. * await context.close(); * ``` * * @public */ export class BrowserContext extends EventEmitter { /** * @internal */ constructor() { super(); } /** * Gets all active {@link Target | targets} inside this * {@link BrowserContext | browser context}. */ targets() { throw new Error('Not implemented'); } overridePermissions() { throw new Error('Not implemented'); } /** * Clears all permission overrides for this * {@link BrowserContext | browser context}. * * @example Clearing overridden permissions in the * {@link Browser.defaultBrowserContext | default browser context}: * * ```ts * const context = browser.defaultBrowserContext(); * context.overridePermissions('https://example.com', ['clipboard-read']); * // do stuff .. * context.clearPermissionOverrides(); * ``` */ clearPermissionOverrides() { throw new Error('Not implemented'); } /** * Whether this {@link BrowserContext | browser context} is closed. */ get closed() { return !this.browser().browserContexts().includes(this); } /** * Identifier for this {@link BrowserContext | browser context}. */ get id() { return undefined; } /** @internal */ [disposeSymbol]() { return void this.close().catch(debugError); } /** @internal */ [asyncDisposeSymbol]() { return this.close(); } } //# sourceMappingURL=BrowserContext.js.map