Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

out of memory c# playwright #34583

Open
falita opened this issue Feb 1, 2025 · 0 comments
Open

out of memory c# playwright #34583

falita opened this issue Feb 1, 2025 · 0 comments

Comments

@falita
Copy link

falita commented Feb 1, 2025

i use these codes to get news real time from a website
its have get news 2000 response per minutes

but after 30 min when i get 100000 news the chromium show this error
"Aw Snap!" Error Code: Out of Memory

see my code
have leak memory or any problem ?
how to solve it ?

` public async Task StartService()
{
var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false
});

 var context = await browser.NewContextAsync();


 var page = await context.NewPageAsync();

 await page.GotoAsync("https://test.com", new PageGotoOptions
 {
     WaitUntil = WaitUntilState.Load  // Ensure full page load
 });
 var signUpButton = page.Locator("text=Sign up for ");
 await signUpButton.WaitForAsync(new LocatorWaitForOptions
 {
     State = WaitForSelectorState.Visible  
 });
 await signUpButton.ClickAsync();
 await Task.Delay(2000);


 await page.Locator("//input[@name='text']").ClickAsync(); // تمرکز روی input
 await page.Locator("//input[@name='text']").FillAsync("jame_stown51080"); 
 var NextButton = page.Locator("text=Next");
 await NextButton.WaitForAsync(new LocatorWaitForOptions
 {
     State = WaitForSelectorState.Visible 
 });
 await NextButton.ClickAsync();

 await page.WaitForSelectorAsync("//input[@name='password']"); 


 await page.Locator("//input[@name='password']").ClickAsync(); 
 await page.Locator("//input[@name='password']").FillAsync("xxxxxxxxxxxxxxxxxxxxx");


 var loginButton = page.Locator("[data-testid='LoginForm_Login_Button']");
 await loginButton.ClickAsync();


 try
 {

     page.Response += async (_, response) =>
     {
         if (response.Ok && response.Url.Contains("SearchTimeline"))
         {
             indexViewModel.Response_Count++;

             var body = await response.TextAsync();
             await GeNews(body);
          
             body = null;
             response = null;
        
             GC.Collect();
             GC.WaitForPendingFinalizers();
           
             await page.Mouse.WheelAsync(0, 10);
         }
     };
     await page.WaitForSelectorAsync("[data-testid='cellInnerDiv']");  // Replace with actual test ID

     await page.WaitForLoadStateAsync(LoadState.Load);



 }
 catch (Exception ex)
 {

     throw;
 }

}`

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

No branches or pull requests

1 participant