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

Help test the raw TCP wireless backend #349

Closed
yume-chan opened this issue Dec 13, 2021 · 12 comments
Closed

Help test the raw TCP wireless backend #349

yume-chan opened this issue Dec 13, 2021 · 12 comments
Assignees
Labels
help wanted Extra attention is needed type:enhancement New feature or request
Milestone

Comments

@yume-chan
Copy link
Owner

yume-chan commented Dec 13, 2021

Direct Sockets API (formerly, "raw sockets API") (Chrome Platform Status) allows Web applications to create raw TCP or UDP sockets .

It has been implemented in Chrome for quite a while, but because the uncertainty and unsolved problems in the spec, it never been enabled.

To enable Direct Sockets API in a Chromium-based browser:

  • Chromium before 98: add --enable-features=DirectSockets command line arguments.
  • Chromium 98 and after: also add --restricted-api-origins=https://www.example.com to command line arguments, or set allowed origins from chrome://flags/#restricted-api-origins. (replace https://www.example.com with real origin using the Direct Sockets API, to add multiple origins, separates them with comma)

It should be possible to create an ADB backend using this API to achieve plugin-free wireless connection.

@yume-chan
Copy link
Owner Author

To protect websites using Direct Sockets API being hijacked and creates unwanted sockets, Chrome requires the website to opt-in a more strict site isolation by returning the following HTTP response headers:

Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp

For detailed explanation, see Why you need "cross-origin isolated" for powerful features.

@yume-chan
Copy link
Owner Author

yume-chan commented Dec 13, 2021

I have pushed a change to enable the Direct Sockets API. But because GitHub Pages doesn't add the above HTTP response headers, and there is no way to configure this, I deployed another website on Vercel: https://ya-webadb.vercel.app/

If you follow the enable steps above (replace https://www.example.com with https://ya-webadb.vercel.app), you can test it now.


If your device doesn't have ADB over WiFi enabled, you can first connect via USB and enable it in the "ADB over WiFi" page:

image

  1. Check the toggle button next to service.adb.tcp.port
  2. (Optionally) change the port number
  3. Click "Apply" button in the menu bar, you device will be disconnected because the ADB daemon restarted.

  1. To connect via Direct Sockets, first find out your device's IP address.
  2. In the drop down menu of "Add" button, you should see "Direct Sockets TCP" option.
    image
  3. Input your devices IP address and ADB port when prompted.
    image
  4. Click "Connect", Chrome will pop up a "Connection Dialog". It's normal for the port input to be empty. Don't change anything, just click "OK"
    image

Known Issues:

  • File download doesn't work because the strict site isolation
  • Can't delete WebSocket or TCP backends

@yume-chan yume-chan mentioned this issue Dec 13, 2021
39 tasks
@yume-chan
Copy link
Owner Author

yume-chan commented Dec 13, 2021

Note: The Direct Sockets spec and the requirement for enabling it may change at any time.

@yume-chan yume-chan added the type:enhancement New feature or request label Dec 13, 2021
@yume-chan yume-chan self-assigned this Dec 13, 2021
@yume-chan yume-chan changed the title Implement a raw TCP backend using Direct Sockets API Help test the raw TCP wireless backend Dec 13, 2021
@yume-chan yume-chan added the help wanted Extra attention is needed label Dec 13, 2021
@yume-chan yume-chan pinned this issue Jan 16, 2022
@yume-chan
Copy link
Owner Author

yume-chan commented Mar 31, 2022

The requirements have changed in Chromium/Chrome Dev/Chrome Canary released after March 15th (See WICG/direct-sockets#35 (comment), ref https://source.chromium.org/chromium/chromium/src/+/main:content/browser/web_exposed_isolation_info.h;l=32;drc=401f9911c6a32a0900f3968258393a9e729da625;bpv=0;bpt=1)

If the steps in #349 (comment) doesn't work, try the new steps:

  1. Lunch chrome with --restricted-api-origins=https://ya-webadb.vercel.app/scrcpy command line arguments (or adding https://ya-webadb.vercel.app/scrcpy to chrome://flags/#restricted-api-origins)
  2. Open https://ya-webadb.vercel.app/scrcpy
  3. Press "Menu -> More Tools -> Create Shortcut..."
  4. Check "Open as window", Press "OK"
  5. Close the newly opened window
  6. Open the app from Start/Launchpad/wherever your apps are

@teefort
Copy link

teefort commented Mar 31, 2022

The requirements have changed in mid-March (See WICG/direct-sockets#35 (comment))

The new steps are:

  1. Lunch chrome with --restricted-api-origins=https://ya-webadb-k2o0yviof-yume-chan.vercel.app command line arguments (or adding https://ya-webadb-k2o0yviof-yume-chan.vercel.app to chrome://flags/#restricted-api-origins)
  2. Open https://ya-webadb-k2o0yviof-yume-chan.vercel.app
  3. Press "Menu -> More Tools -> Create Shortcut..."
  4. Check "Open as window", Press "OK"
  5. Close the newly opened window
  6. Open the app from Start/Launchpad/wherever your apps are

I just tried these steps, and I'm still only seeing USB and WebSocket from the Add dropdown. Would you be able to provide some help?

This is what restricted-api-origins looks like for me
image

I created the shortcut in a new window, closed it, and then launched it from the shortcut.

@yume-chan
Copy link
Owner Author

The new steps only apply to Chrome Dev/Canary/Chromium versions after March 15th. I don't know if any Stable/Beta versions are shipped with this change. So also try the old steps.

In fact, all versions released between Feb 15th and Marth 15th have DirectSockets feature disabled (by mistake). Stable/Beta are most possible in this range.

If you are using Microsoft Edge Dev/Canary, the code sometimes lags behind Chromium for about 10 days. So it is even harder to guess.

@yume-chan yume-chan added this to the Backlog milestone Apr 3, 2022
@ziyunfei
Copy link

ziyunfei commented Jul 30, 2022

Just FYI: restricted-api-origins has been renamed to isolated-app-origins.

chromium/chromium@8a471ec

@blackwiz4rd
Copy link

Hello all,
thanks for the great project,
after steps from comment:

I also don't see any Direct Sockets button.
Here is my version (google-chrome-stable arch linux)
`

Google Chrome 109.0.5414.74 (Official Build) (64-bit)
Revision e7c5703604daa9cc128ccf5a5d3e993513758913-refs/branch-heads/5414@{#1172}
OS Linux
JavaScript V8 10.9.194.9

`

Any idea why?

@glitch128
Copy link

are you on the stable channel?

@blackwiz4rd
Copy link

blackwiz4rd commented Jan 31, 2023

are you on the stable channel?

Yes, I should be: https://aur.archlinux.org/packages/google-chrome

@glitch128
Copy link

I have tried it on chromeOS stable 109, and it doesn't work.

The new steps only apply to Chrome Dev/Canary/Chromium versions after March 15th. I don't know if any Stable/Beta versions are shipped with this change. So also try the old steps.

@yume-chan
Copy link
Owner Author

The Direct Sockets spec changed dramatically in July last year. The new security model is fundamentally breaking many popular React framework and libraries, including some I'm using.

Also, Google Chrome haven't implemented WebUSB in the new model, so can't use both at the same time.

Closing this test as now. Will try to experiment again when the proposal is more mature.

@yume-chan yume-chan unpinned this issue Jan 31, 2023
Repository owner locked as resolved and limited conversation to collaborators Feb 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed type:enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants