Repository: puppeteer/puppeteer
File: packages/puppeteer-core/src/common/EmulationManager.ts (TypeScript)

Code before:
    active: false,
  };
  #javascriptEnabledState: JavascriptEnabledState = {
    javaScriptEnabled: true,
    active: false,
  };

  #secondaryClients = new Set<CDPSession>();

  constructor(client: CDPSession) {
    this.#client = client;
  }

  updateClient(client: CDPSession): void {
    this.#client = client;
    this.#secondaryClients.delete(client);
  }

  async registerSpeculativeSession(client: CDPSession): Promise<void> {
    this.#secondaryClients.add(client);
    client.once(CDPSessionEmittedEvents.Disconnected, () => {
      return this.#secondaryClients.delete(client);
    });
    // We don't await here because we want to register all state changes before
    // the target is unpaused.
    void this.#viewportState.sync();
    void this.#syncIdleState().catch(debugError);
    void this.#syncTimezoneState().catch(debugError);
    void this.#syncVisionDeficiencyState().catch(debugError);
    void this.#syncCpuThrottlingState().catch(debugError);
    void this.#syncMediaFeaturesState().catch(debugError);
    void this.#syncMediaTypeState().catch(debugError);
    void this.#syncGeoLocationState().catch(debugError);
    void this.#syncDefaultBackgroundColorState().catch(debugError);
    void this.#syncJavaScriptEnabledState().catch(debugError);
  }

  get javascriptEnabled(): boolean {
    return this.#javascriptEnabledState.javaScriptEnabled;
  }

  clients(): CDPSession[] {
    return [this.#client, ...Array.from(this.#secondaryClients)];
  }

  async emulateViewport(viewport: Viewport): Promise<boolean> {
    await this.#viewportState.setState({
      viewport,
      active: true,
    });


Review comment (bug):
```suggestion
    void this.#viewportState.sync().catch(debugError);
```

Code after:
    active: false,
  };
  #javascriptEnabledState: JavascriptEnabledState = {
    javaScriptEnabled: true,
    active: false,
  };

  #secondaryClients = new Set<CDPSession>();

  constructor(client: CDPSession) {
    this.#client = client;
  }

  updateClient(client: CDPSession): void {
    this.#client = client;
    this.#secondaryClients.delete(client);
  }

  async registerSpeculativeSession(client: CDPSession): Promise<void> {
    this.#secondaryClients.add(client);
    client.once(CDPSessionEmittedEvents.Disconnected, () => {
      return this.#secondaryClients.delete(client);
    });
    // We don't await here because we want to register all state changes before
    // the target is unpaused.
    void this.#viewportState.sync().catch(debugError);
    void this.#syncIdleState().catch(debugError);
    void this.#syncTimezoneState().catch(debugError);
    void this.#syncVisionDeficiencyState().catch(debugError);
    void this.#syncCpuThrottlingState().catch(debugError);
    void this.#syncMediaFeaturesState().catch(debugError);
    void this.#syncMediaTypeState().catch(debugError);
    void this.#syncGeoLocationState().catch(debugError);
    void this.#syncDefaultBackgroundColorState().catch(debugError);
    void this.#syncJavaScriptEnabledState().catch(debugError);
  }

  get javascriptEnabled(): boolean {
    return this.#javascriptEnabledState.javaScriptEnabled;
  }

  clients(): CDPSession[] {
    return [this.#client, ...Array.from(this.#secondaryClients)];
  }

  async emulateViewport(viewport: Viewport): Promise<boolean> {
    await this.#viewportState.setState({
      viewport,
      active: true,
    });