Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Commands/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,16 @@ private static bool TryParseWebCommandOptions(WebCommand command, string[] args,
{
command.SearchProvider = WebSearchProvider.Bing;
}
else if (arg == "--wait-for")
{
var selectors = GetInputOptionArgs(i + 1, args);
if (selectors.Count() == 0)
{
throw new CommandLineException($"Missing CSS selectors for {arg}");
}
command.WaitForSelectors.AddRange(selectors);
i += selectors.Count();
}
else if (arg == "--duck-duck-go" || arg == "--duckduckgo")
{
command.SearchProvider = WebSearchProvider.DuckDuckGo;
Expand Down
3 changes: 3 additions & 0 deletions src/Commands/WebCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ public WebCommand()
public List<Tuple<string, string>> PageInstructionsList;

public string SavePageOutput { get; set; }

// List of CSS selectors to wait for before proceeding
public List<string> WaitForSelectors { get; set; } = new();
}
18 changes: 17 additions & 1 deletion src/Helpers/PlaywrightHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static async Task<List<string>> GetWebSearchResultUrlsAsync(string search
return urls;
}

public static async Task<(string, string)> GetPageAndTitle(string url, bool stripHtml, string saveToFolder, BrowserType browserType, bool interactive)
public static async Task<(string, string)> GetPageAndTitle(string url, bool stripHtml, string saveToFolder, BrowserType browserType, bool interactive, List<string> waitForSelectors = null)
{
// Initialize Playwright
using var playwright = await Playwright.CreateAsync();
Expand All @@ -59,6 +59,22 @@ public static async Task<List<string>> GetWebSearchResultUrlsAsync(string search
// Navigate to the URL
await page.GotoAsync(url);

// Wait for selectors if specified
if (waitForSelectors?.Any() == true)
{
foreach (var selector in waitForSelectors)
{
try
{
await page.WaitForSelectorAsync(selector, new() { Timeout = 30000 });
}
catch (TimeoutException)
{
throw new Exception($"Timeout waiting for selector '{selector}' after 30000ms");
}
}
}

// Fetch the page content and title
var content = await FetchPageContent(page, url, stripHtml, saveToFolder);
var title = await page.TitleAsync();
Expand Down
4 changes: 4 additions & 0 deletions src/assets/help/web get examples.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ EXAMPLES

mdx web get https://example.com https://mbers.us/bio --instructions "style example.com as the other site"

EXAMPLE 5: Wait for dynamic content to load

mdx web get https://example.com --wait-for "#main-content" ".dynamic-widget"

SEE ALSO

mdx help web get
Expand Down
1 change: 1 addition & 0 deletions src/assets/help/web get options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ OPTIONS
--firefox Use Firefox browser
--webkit Use WebKit browser
--strip Strip HTML tags from downloaded content (default: false)
--wait-for SELECTOR [...] Wait for specified CSS selectors to be present before proceeding

AI PROCESSING

Expand Down