Skip to content

Bugfix/Headless Execution Default Size #4292

Merged
GokulBothe99 merged 4 commits into
Releases/Betafrom
BugFix/HeadlessResolution
Sep 5, 2025
Merged

Bugfix/Headless Execution Default Size #4292
GokulBothe99 merged 4 commits into
Releases/Betafrom
BugFix/HeadlessResolution

Conversation

@GokulBothe99

@GokulBothe99 GokulBothe99 commented Sep 3, 2025

Copy link
Copy Markdown
Contributor

Thank you for your contribution.
Before submitting this PR, please make sure:

  • PR description and commit message should describe the changes done in this PR
  • Verify the PR is pointing to correct branch i.e. Release or Beta branch if the code fix is for specific release , else point it to master
  • Latest Code from master or specific release branch is merged to your branch
  • No unwanted\commented\junk code is included
  • No new warning upon build solution
  • Code Summary\Comments are added to my code which explains what my code is doing
  • Existing unit test cases are passed
  • New Unit tests are added for your development
  • Sanity Tests are successfully executed for New and Existing Functionality
  • Verify that changes are compatible with all relevant browsers and platforms.
  • After creating pull request there should not be any conflicts
  • Resolve all Codacy comments
  • Builds and checks are passed before PR is sent for review
  • Resolve code review comments
  • Update the Help Library document to match any feature changes

Summary by CodeRabbit

  • New Features

    • Consistent headless viewport defaults: Selenium uses 1080x1920 when headless or on Linux without explicit dimensions; Playwright uses 1920x1080 in headless mode.
    • Browser launch arguments now built dynamically to choose maximized (non-headless) or fixed-size (headless).
  • Style

    • Minor formatting and whitespace cleanup.

@coderabbitai

coderabbitai Bot commented Sep 3, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

PlaywrightDriver now builds launch args dynamically, adding a headless window-size flag when HeadlessBrowserMode is enabled. SeleniumDriver's StartDriver sets a deterministic 1080x1920 window when running headless (or on Linux) and no explicit BrowserWidth/BrowserHeight are provided. No public APIs changed.

Changes

Cohort / File(s) Summary of Changes
Playwright headless args handling
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs
Replaced hard-coded Args with a local list initialized with "--start-maximized"; append "--window-size=1920,1080" when HeadlessBrowserMode is true; set Options.Args = args.ToArray(); minor formatting change.
Selenium headless sizing logic
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs
In StartDriver, when BrowserHeight/BrowserWidth are not provided and (HeadlessBrowserMode is true or OS is Linux), set window size to 1080x1920 instead of maximizing; minor whitespace tweak.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant T as Test Runner
  participant PD as PlaywrightDriver
  participant SD as SeleniumDriver
  participant B as Browser

  rect rgba(220,235,255,0.25)
  note over PD: Playwright start flow
  T->>PD: StartDriver()
  PD->>PD: args = ["--start-maximized"]
  alt Headless
    PD->>PD: args += ["--window-size=1920,1080"]
  end
  PD->>B: Launch with Options.Args = args
  end

  rect rgba(235,255,220,0.25)
  note over SD: Selenium start flow
  T->>SD: StartDriver()
  alt Headless or Linux AND no explicit size
    SD->>B: launch/set window 1080x1920
  else size provided or not headless
    SD->>B: maximize or use provided size
  end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • Maheshkale447

Poem

I twitch my nose and tweak my args,
A maximized hop, no cloudy snags.
Headless windows set with care,
1920 by 1080 — steady air.
Rabbity builds, launched with flair. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch BugFix/HeadlessResolution

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (2)

329-355: Units bug: seconds vs. milliseconds mix leads to 1000x timeouts

Here browserOptions.Timeout is treated as ms elsewhere, but this block interprets/assigns it as seconds and then multiplies again when invoking the handler, causing excessive waits.

-                        float? driverDefaultTimeout1 = browserOptions.Timeout;
-                        float waitUntilTime;
-                        if (act.Timeout > 0)
-                        {
-                            waitUntilTime = act.Timeout.GetValueOrDefault();
-                        }
-                        else if(browserOptions.Timeout>0)
-                        {
-                            waitUntilTime = browserOptions.Timeout.Value;
-                        }
-                        else
-                        {
-                            waitUntilTime = 5;
-                        }
-                        browserOptions.Timeout = waitUntilTime;
+                        float? driverDefaultTimeout1 = browserOptions.Timeout; // stored in ms
+                        float waitMs;
+                        if (act.Timeout > 0)
+                        {
+                            // act.Timeout is in seconds → convert to ms
+                            waitMs = act.Timeout.Value * 1000f;
+                        }
+                        else if (browserOptions.Timeout > 0)
+                        {
+                            // already ms
+                            waitMs = browserOptions.Timeout.Value;
+                        }
+                        else
+                        {
+                            waitMs = 5000f; // default 5s in ms
+                        }
+                        browserOptions.Timeout = waitMs;
                         try
                         {                          
-                            actWebSmartSyncHandler.HandleAsync(act, waitUntilTime*1000).Wait();
+                            actWebSmartSyncHandler.HandleAsync(act, (int)waitMs).Wait();
                         }

Please confirm elsewhere that browserOptions.Timeout is consistently treated as milliseconds.


614-621: fullPage flag inverted in screenshot logic

fullPage=true should call the full-page API; it is currently swapped.

-                if (fullPage)
-                {
-                    screenshot = await tab.ScreenshotAsync();
-                }
-                else
-                {
-                    screenshot = await tab.ScreenshotFullPageAsync();
-                }
+                if (fullPage)
+                {
+                    screenshot = await tab.ScreenshotFullPageAsync();
+                }
+                else
+                {
+                    screenshot = await tab.ScreenshotAsync();
+                }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between fd572e4 and 09ac8ed.

📒 Files selected for processing (2)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (2 hunks)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowser.cs (3)
  • PlaywrightBrowser (24-88)
  • PlaywrightBrowser (55-63)
  • Options (29-42)
🔇 Additional comments (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (1)

143-146: Args/Timeout wiring looks good

Args now flow from the built list; Timeout conversion to ms is consistent with other usages. No concerns here.

Comment thread Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (3)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (2)

740-744: Trim trailing spaces and set Firefox headless size via args.

  • Trailing whitespace after the headless arg.
  • Also ensure deterministic headless viewport on CI by setting width/height flags when no explicit size is provided.

Apply for the whitespace:

-                            FirefoxOption.AddArgument("--headless");                           
+                            FirefoxOption.AddArgument("--headless");

Additionally (outside this hunk), consider:

// After adding --headless for Firefox
if ((HeadlessBrowserMode || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) &&
    string.IsNullOrEmpty(BrowserHeight) && string.IsNullOrEmpty(BrowserWidth))
{
    FirefoxOption.AddArgument("--width=1920");
    FirefoxOption.AddArgument("--height=1080");
}

1124-1127: Broaden condition and inject Chromium window-size to avoid 800×600 in headless/Linux.

This branch misses Linux runs where headless is forced earlier; and Convert.ToInt32 is unnecessary. Also add options-level window-size for Chromium to ensure the viewport matches.

-                else if (HeadlessBrowserMode)
-                {
-                    Driver.Manage().Window.Size = new Size() { Height = Convert.ToInt32(1080), Width = Convert.ToInt32(1920) };
-                }
+                else if (HeadlessBrowserMode || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+                {
+                    Driver.Manage().Window.Size = new Size(width: 1920, height: 1080);
+                }

Additionally (outside this hunk):

  • Chrome/Brave (in configChromeDriverAndStart, after adding headless):
if ((HeadlessBrowserMode || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) &&
    string.IsNullOrEmpty(BrowserHeight) && string.IsNullOrEmpty(BrowserWidth))
{
    options.AddArgument("--window-size=1920,1080");
}
  • Edge (in Edge options block, after adding headless):
if ((HeadlessBrowserMode || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) &&
    string.IsNullOrEmpty(BrowserHeight) && string.IsNullOrEmpty(BrowserWidth))
{
    EDOpts.AddArgument("--window-size=1920,1080");
}
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (1)

134-140: Headless: drop ineffective --start-maximized; align default size and gate --window-size by engine

  • In headless, "--start-maximized" is ignored; keep it only for headed launches.
  • Current default "1920,1080" diverges from Selenium’s reported "1080,1920". Standardize to avoid visual/regression baseline drift.
  • "--window-size" is Chromium/Edge-specific; Firefox ignores it in headless—set viewport via Playwright context for cross-browser consistency.

Apply this diff locally; I can follow up with a viewport patch for Firefox/WebKit in PlaywrightBrowser if desired.

-            var args = new List<string> { "--start-maximized" };
-
-            if (HeadlessBrowserMode)
-            {
-                args.Add("--window-size=1920,1080");
-            }
+            var args = new List<string>();
+            if (HeadlessBrowserMode)
+            {
+                // Align with Selenium default and restrict to Chromium-based browsers
+                if (BrowserType is WebBrowserType.Chrome or WebBrowserType.Edge)
+                {
+                    args.Add("--window-size=1080,1920");
+                }
+                // For Firefox/WebKit, set viewport in the Playwright context (not via args).
+            }
+            else
+            {
+                args.Add("--start-maximized");
+            }

Validation script to confirm Selenium’s headless default and avoid regressions:

#!/usr/bin/env bash
set -euo pipefail
# Find Selenium driver sizing logic and print nearby context
fd -t f -i 'SeleniumDriver.cs' | while read -r f; do
  echo "==> $f"
  rg -n -C3 -e 'window[- ]?size|SetWindowSize|Viewport|Width|Height|1080|1920|Headless' "$f" || true
done
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 09ac8ed and 6c957bb.

📒 Files selected for processing (2)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (2 hunks)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-09-04T11:19:44.679Z
Learnt from: prashelke
PR: Ginger-Automation/Ginger#4294
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs:10651-10658
Timestamp: 2025-09-04T11:19:44.679Z
Learning: In Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs, maintainer prefers not to keep the helper IsSvgElementByWebElement(IWebElement); rely on the existing enum-based IsSvgElement(eElementType) helper instead. Future reviews should not reintroduce IsSvgElementByWebElement.

Applied to files:

  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs
📚 Learning: 2025-09-04T09:55:20.522Z
Learnt from: prashelke
PR: Ginger-Automation/Ginger#4294
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs:5789-5796
Timestamp: 2025-09-04T09:55:20.522Z
Learning: In Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (around line 5786), maintainer prashelke prefers to keep the helper method `IsSvgElement(eElementType)` as-is (no inlining or renaming), even though it currently checks only for `eElementType.Svg`. Future reviews should not suggest removing or renaming this helper.

Applied to files:

  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs
🧬 Code graph analysis (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowser.cs (3)
  • PlaywrightBrowser (24-88)
  • PlaywrightBrowser (55-63)
  • Options (29-42)
🔇 Additional comments (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightDriver.cs (1)

143-143: Args hookup looks good

Passing the dynamically built args array into options is correct.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (1)

740-744: Trim trailing whitespace and set headless defaults for Firefox.

  • Trailing spaces after the headless argument. Same nit as earlier.
  • While here, set width/height when running headless and no explicit size is provided to make the viewport deterministic.
-                            FirefoxOption.AddArgument("--headless");                           
+                            FirefoxOption.AddArgument("--headless");
+                            if (string.IsNullOrEmpty(BrowserHeight) && string.IsNullOrEmpty(BrowserWidth))
+                            {
+                                FirefoxOption.AddArgument("--width=1920");
+                                FirefoxOption.AddArgument("--height=1080");
+                            }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6c957bb and 3a69004.

📒 Files selected for processing (1)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs (2 hunks)

@GokulBothe99
GokulBothe99 merged commit 124dd5a into Releases/Beta Sep 5, 2025
14 of 17 checks passed
@GokulBothe99
GokulBothe99 deleted the BugFix/HeadlessResolution branch September 5, 2025 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants