mechanical-orchard / playwright-elixir

An Elixir library for Playwright web automation
MIT License
107 stars 21 forks source link

New function - Abort #41

Open oliver-kriska opened 2 years ago

oliver-kriska commented 2 years ago

Hello, I would like to ask you about implementation abort function so we can skip some resources to load, especially in my case images and videos. I made this function here: https://github.com/geometerio/playwright-elixir/blob/ab729b6f6f1f4f6d9e238d5e97598757b968c548/lib/playwright/route.ex#L14-L15

@spec abort(t(), binary()) :: :ok
  defp abort(%Route{session: session} = route, error_code \\ nil) do
    Channel.post(session, {:guid, route.guid}, :abort, %{error_ode: error_code})
  end

and implementation:

Playwright.Page.route(page_loader, "**/*", fn route, request ->
      if request.resource_type in ["image", "font"] do
        Playwright.Route.abort(route, "blockedbyclient")
      else
        Playwright.Route.continue(route)
      end
    end)

But it crash server, I very new in playwright so not sure where can be problem.

Doc for abort is here and my code is here

coreyti commented 1 year ago

Hi @oliver-kriska, a quick note:

@lexun and I were taking a look at this yesterday. It turns out that the immediate fix/implementation for Route.abort/2 as you implemented is not too difficult[^1], but we discovered some fun edge-case bugs while working on that.

So, thanks for creating this GitHub issue! It's going to lead to additional improvements. I hope to get those out shortly. And, thank you @lexun for your eyes and contributions on this.

Work in progress.

[^1]: indeed, I believe that you solved it later in your fork.