fix(chromium): apply offline mode to pages created in offline context - #42177
Open
KARTIK SAHU (yash2277-ctrl) wants to merge 1 commit into
Open
fix(chromium): apply offline mode to pages created in offline context#42177KARTIK SAHU (yash2277-ctrl) wants to merge 1 commit into
KARTIK SAHU (yash2277-ctrl) wants to merge 1 commit into
Conversation
Fixes microsoft#42174 When a page was created on a BrowserContext that already had offline mode enabled via setOffline(true), navigator.onLine incorrectly reported true instead of false. The root cause was that updateOffline() was not being called during page initialization in _initialize(). While updateOffline() was properly called when toggling offline mode on existing pages, newly created pages never received the initial offline state from their parent context. This fix adds updateOffline() to the initialization promise chain, ensuring that pages born into an offline context correctly reflect the offline state from the start, making navigator.onLine === false as expected. The fix only affects Chromium, as the offline state is applied during page initialization alongside other context options like geolocation, user agent, and emulated media. Testing: - Pages created after setOffline(true) now report navigator.onLine === false - Toggling offline on existing pages continues to work - No impact on pages created in online contexts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a bug where pages created in an already-offline BrowserContext incorrectly report navigator.onLine === true instead of false.
Fixes
Closes #42174
Problem
When creating a page on a BrowserContext that already has offline mode enabled:
Toggling offline on existing pages works correctly.
Root Cause
During page initialization in FrameSession._initialize(), the offline state from the parent context was never applied to the new page. While other context options like geolocation, user agent, and emulated media were properly applied during initialization, updateOffline() was missing from the initialization chain.
Solution
Added this._crPage.updateOffline() to the initialization promise chain in _initialize(), ensuring new pages receive their parent context's offline state during setup.
Changes
Impact
Testing
Tested with the repro from #42174:
`javascript
const { chromium } = require('@playwright/test');
(async () => {
const browser = await chromium.launch();
const context = await browser.newContext();
await context.setOffline(true);
const page = await context.newPage();
const result = await page.evaluate(() => navigator.onLine);
console.log(result); // Now correctly returns false
await browser.close();
})();
`
Type of Change