Title: fix(inspector): serve source map streams the way Chromium does by edusperoni · Pull Request #2091 · NativeScript/android · GitHub
Open Graph Title: fix(inspector): serve source map streams the way Chromium does by edusperoni · Pull Request #2091 · NativeScript/android
X Title: fix(inspector): serve source map streams the way Chromium does by edusperoni · Pull Request #2091 · NativeScript/android
Description: Source maps served through nsruntime:// (Network.loadNetworkResource + IO.read/IO.close) now follow Chromium's own implementation (DevToolsStreamFile, IOHandler, NetworkHandler::OnLoadNetworkResourceFinished), so VS Code's js-debug and Chrome DevTools see the same behavior they get from Chrome. Same change as NativeScript/ios#548.
What was wrong
Split characters. IO.read cut the stream every 1 MB without regard for UTF-8. js-debug decodes each chunk on its own, so a character straddling a boundary came out as two U+FFFD in sourcesContent. Breakpoints still bound (mappings are ASCII); the source text js-debug showed was garbled.
Streams never freed during a session. js-debug only sends IO.close when the response has a Content-Length header, and none was sent, so every map it loaded stayed in memory until the debugger disconnected.
offset was ignored, so only clients that read front to back worked.
Behavior now (matches Chromium)
Before
Now
Chunk end
every 1 MB
a chunk > 6 bytes is trimmed back to the end of its last whole character (port of base::TruncateUTF8ToByteSize)
Encoding
always base64
text when the whole file is valid UTF-8 (base::IsStringUTF8, which also rejects noncharacters), base64 otherwise; see below for chunks that cut a character
offset
ignored
honored; missing or negative continues from the last read; past the end is eof
offset/size type
any integer, out-of-range wraps
int32, as in Chromium's bindings (5.0 counts); otherwise -32602 Invalid parameters
size <= 0
treated as default
-32602 Invalid max read size
IO.close unknown handle
success
-32602 Invalid stream handle
Stream lifetime
until IO.close or disconnect
same (Chromium never frees on eof either)
loadNetworkResource headers
none
Content-Length, Content-Type: application/json
Honoring offset is safe only together with the boundary trimming. js-debug advances its offset by the UTF-8 length of each decoded chunk, which ran ahead of the real position whenever a character was split.
Three choices differ from a literal copy of Chrome:
Headers. Chrome's file:// loader sends no Content-Length, so Chrome has the same js-debug leak for file-backed maps. The reply here carries what an HTTP server would send for the file.
Chunks that cut a character. A read that starts inside a character, or one of 6 bytes or fewer, can cut a character at an end. Chrome's JSON encoder drops those bytes. Here that one reply is sent as base64 with the exact bytes (base64Encoded is per reply). js-debug and DevTools never read this way.
Chunk size. The default stays at 1 MB instead of Chromium's 10 MB to keep socket frames and peak memory small on device.
Streams are still dropped on every disconnect: connect() always runs disconnect() first, and websocket close and error both call it. That matches Chromium's DiscardAllStreams on detach.
Text chunks now carry raw UTF-8, including 4-byte sequences, back to Java through NewStringUTF, like the V8 inspector messages already do. CheckJNI raised no complaint on API 33.
Testing
Device suite on a ci_repro_api33 arm64 emulator, run twice: 238 suites, 1468 tests, 0 failures, 4 skipped.
An end-to-end CDP client (not committed) over the forwarded
Open Graph Description: Source maps served through nsruntime:// (Network.loadNetworkResource + IO.read/IO.close) now follow Chromium's own implementation (DevToolsStreamFile, IOHandler, NetworkHandler::OnLoadNetworkRe...
X Description: Source maps served through nsruntime:// (Network.loadNetworkResource + IO.read/IO.close) now follow Chromium's own implementation (DevToolsStreamFile, IOHandler, NetworkHandler::OnLoadNetwo...
Opengraph URL: https://github.com/NativeScript/android/pull/2091
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:3fb9fa44-b721-e57b-65ba-f35a1339d57d |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A7C6:1C6C3E:17190C6:1E7154E:6B013433 |
| html-safe-nonce | 71053ed0b6b5f2982c7f9f8860d3b960936e8c3cc9cfa59bd83bb8a9047f7cec |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBN0M2OjFDNkMzRToxNzE5MEM2OjFFNzE1NEU6NkIwMTM0MzMiLCJ2aXNpdG9yX2lkIjoiMTk2Njg2NzQ0NTkzMTEyNzg1OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 82e109e679b964fcbe3be06e6d32616e964fcecba5f6a1d54944e2057f354022 |
| hovercard-subject-tag | pull_request:5192328058 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/NativeScript/android/pull/2091/files |
| twitter:image | https://avatars.githubusercontent.com/u/4061767?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/4061767?s=400&v=4 |
| og:image:alt | Source maps served through nsruntime:// (Network.loadNetworkResource + IO.read/IO.close) now follow Chromium's own implementation (DevToolsStreamFile, IOHandler, NetworkHandler::OnLoadNetworkRe... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/NativeScript/android git https://github.com/NativeScript/android.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 29137950 |
| octolytics-dimension-repository_nwo | NativeScript/android |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 29137950 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/android |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width