Code Monkey home page Code Monkey logo

chromium-bidi's Issues

WebDriver BiDi clients implement cross-browser e2e scenario: Google Search

Cross-browser e2e scenario of

  1. loading Google.com
  2. entering a search term via keyboard input
  3. submitting via mouse click
  4. extracting the results from the page.

This includes

  • WebDriver BiDi specification.
  • WPT tests.
  • Implementations in Chromium passing the WPT tests.
  • Implementations in Firefox passing the WPT tests.
  • Implementations in Safari passing the WPT tests.
  • Support in Puppeteer.

Support multiple CdpClients with different CDP sessionId sharing a connection

We'll need a way to connect a CdpClient to a different CDP target than the browser target. In other words, support the "flat" mode of the protocol where multiple CDP sessions may share a connection and use the "sessionId" property to route messages to a particular session.

This is already used in mapperServer.ts to create and communicate with the mapper tab, and we will likely need it later to attach to related targets such as OOPIFs or workers.

Proposed API: Add a new method to CdpClient:
public attachToSession(sessionId: string): CdpClient

Given an existing CdpClient (e.g. the initial browser client), calling this method returns a new CdpClient that shares the same transport and can be used to send messages to or receive events from the given session.

WebDriver BiDi clients implement cross-browser e2e scenario: print to PDF

Cross-browser e2e scenario of navigating + printing the page to PDF.

Includes:

  • WebDriver BiDi specification.
  • WPT tests.
  • Implementations in Chromium passing the WPT tests.
  • Implementations in Firefox passing the WPT tests.
  • Implementations in Safari passing the WPT tests.
  • Support in Puppeteer.

Switch to targetCreated/targetDestroyed for BiDi contextCreated/contextDestroyed events

The BrowsingContextProcessor is using attachedToTarget and detachedFromTarget to track known browsing contexts and fire contextCreated and contextDestroyed events.

These events are intended to track when a CDP client attaches to or detaches from a Target. This may not always map 1:1 with target creation and target destruction. For example, there can be multiple sessions attached to a Target, some may detach and re-attach, and the target doesn't necessarily go away once all sessions have ended.

This tracks updating BrowsingContextProcessor to use targetCreated/targetDestroyed instead. Note that we're already using targetInfoChanged which is in the same "family" of events as targetCreated/targetDestroyed.

Move serialization to CDP

Specification bases serialization logic on the JS internal slots. E.g. value has a [[DateValue]] internal slot.

In JS there is no way to implement this logic. Current BiDi implementation is based on checking the prototypes, which can lead to incorrect or unwanted results.

The only way to implement the serialization properly according to the spec is to move it to CDP level by adding a field bidiValue to the CDP Runtime.RemoteObject and a flag generateBiDiValue to the CDP Runtime.callFunctionOn method. On the CDP level there is an access to all the internals of the V8, and implementation can be done according to spec.

line number starts from 1 instead of 0 from CDP

In the test case test_consoleLog_logEntryAddedEventEmitted, the line number returned from Bidi server starts from 1. Based on CDP definition of Runtime.CallFrame (link), the lineNumber should start from 0.

Optimize Mapper compiled code

Actual: the rolled-up Mapper script /src/.build/bidiMapper/mapper.js has a size of 748K, and the vast majority of the file is CDP string literals describing CDP methods, which are added for development convenience and are required for the functionality.

Removing those definitions reduces the size of the plain /src/.build/bidiMapper/mapper.js to 68K, and minimizing afterwards leads to only 28K source size.

Expected: the rolled-up Mapper script /src/.build/bidiMapper/mapper.js doesn't have unnecessary string literals and has a size of ~ 30K.

Implement CDP events filtering

Tracking

  • Consider adding filtering CDP.receivedEvent events by session/method/etc in BiDi+.
    • Filtering by Method
    • Filtering by Session
  • Re-add ability to subscribe to all CDP events

WebDriver BiDi clients implement cross-browser e2e scenario: blocking images

Cross-browser e2e scenario of loading a page with images blocked using request interception.

Includes:

  • WebDriver BiDi specification.
  • WPT tests.
  • Implementations in Chromium passing the WPT tests.
  • Implementations in Firefox passing the WPT tests.
  • Implementations in Safari passing the WPT tests.
  • Support in Puppeteer.

Get `examples/cross-browser.py` to run on top of Firefox’s BiDi implementation

With Firefox Nighty:

$ ./firefox --remote-debugging-port=9222
WebDriver BiDi listening on ws://localhost:9222
DevTools listening on ws://localhost:9222/devtools/browser/6cf65b2b-54e9-444e-a36e-0c04f12b47c9
…

$ # in another terminal / tab

$ PORT=9222 python3 examples/cross-browser.py
Traceback (most recent call last):
  File "~/projects/chromium-bidi/examples/cross-browser.py", line 150, in <module>
    result = loop.run_until_complete(main())
  File "~/homebrew/Cellar/[email protected]/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "~/projects/chromium-bidi/examples/cross-browser.py", line 53, in main
    websocket = await get_websocket()
  File "~/projects/chromium-bidi/examples/cross-browser.py", line 28, in get_websocket
    return await websockets.connect(url)
  File "~/Library/Python/3.9/lib/python/site-packages/websockets/client.py", line 542, in __await_impl__
    await protocol.handshake(
  File "~/Library/Python/3.9/lib/python/site-packages/websockets/client.py", line 296, in handshake
    raise InvalidStatusCode(status_code)
websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 200

We should figure out what’s going on here.

Update BigInt format

Currently, BigInt is serialized as {"type":"bigint","value":"12345678901234567168n"} with a trailing n at the end, while in the serialization spec written BigInt should be a result of calling BigInt.toString(), which doesn't have a trailing n character.

once() method for CDP events

There are a few instances of this pattern appearing in our code, used to listen for a single occurrence of an event:

const eventHandler = (params) => {
  cdpClient.Page.removeEventListener('frameStoppedLoading', eventHandler);
  // ... Do stuff ...
};

cdpClient.Page.addEventListener('frameStoppedLoading', eventHandler);

We could add a .once() method to encapsulate this pattern instead:

const params = await cdpClient.Page.once('frameStoppedLoading');
// ... Do stuff ...

Support both a "standalone" and "embedded" build

Idea: Support building/running the bidi mapper in two configurations:

  • "embedded" - This is the current configuration. Mapper is injected into a browser tab and communicates with the rest of the browser through exposeDevToolsProtocol.
  • "standalone" - New config. Mapper runs as a node module outside the browser and communicates with the browser through remote-debugging-port/pipe.

Motivation:

Standalone mode would simplify development and testing of mapper code. The bidi server code and mapper code would all run in the same node process which simplifies debugging.

Use sessionId instead of targetId to associate CDP client with a Context

The _handleDetachedFromTargetEvent function in browsingContextProcessor.ts uses the targetId parameter on the detachedFromTarget event which is depreacted. The sessionId parameter is recommended instead. This is likely because CDP supports multiple CDP sessions attached to the same Target (although we only use 1 CDP session for our purposes).

This tracks updating our code to use the sessionId parameter here instead. We would likely need to maintain a map in the browsingContextProcessor mapping CDP session IDs to Context objects.

Prototype `binding` type of `LocalValue`

w3c/webdriver-bidi#157

Instead of adding global bindings, pass bindings as deserializable arguments to script.callFunction.
...
The argument can be something like:

{
  type: "binding", 
  value: "SOME_BINDING_NAME"
}

, which will be deserialized to a callback. Calling that callback with any arguments will cause the BiDi event with those arguments like:

{
  method: "script.bindingCalled",
  params: {
    arguments: [... remote values ...],
    name: "SOME_BINDING_NAME"
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.