Skip to content

Debug PHP in browser Devtools (XDebug <-> CDP Bridge) #2288

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

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

adamziel
Copy link
Collaborator

Motivation for the change, related issues

An XDebug <-> CDP bridge to debug PHP code in the browser:

CleanShot.2025-06-19.at.01.59.06.mp4

Implementation details

I've asked o3-pro to build it, applied a few tweaks, and voila – we have a a demo :-)

Testing Instructions (or ideally a Blueprint)

  • Apply the JSPI PR and this PR.
  • Make sure you're running Node v23+
  • Run:
node --experimental-wasm-stack-switching --experimental-wasm-jspi --loader=./packages/meta/src/node-es-module-loader/loader.mts  packages/xdebug/protocol.ts

The script will guide you from there

Problems

When eval is called, PHP crashes like below. It may be a bridge problem or XDebug problem:

[XDebug][send] eval -- JGNvbnN0cw==
Error: resolved is not a function
    at runExecutionFunction (file:///Users/cloudnik/www/Automattic/core/plugins/playground/packages/php-wasm/universal/src/lib/php.ts:971:22) {
  cause: TypeError: resolved is not a function
      at stubs.<computed> (file:///Users/cloudnik/www/Automattic/core/plugins/playground/packages/php-wasm/node/jspi/php_8_4.js:1296:15)
      at wasm://wasm/000ef1e6:wasm-function[545]:0x203cc
      at wasm://wasm/000ef1e6:wasm-function[604]:0x26320
      at wasm://wasm/000ef1e6:wasm-function[574]:0x228d0
      at wasm://wasm/000ef1e6:wasm-function[578]:0x232ca
      at wasm://wasm/000ef1e6:wasm-function[549]:0x20966
      at wasm://wasm/000ef1e6:wasm-function[219]:0xa209
      at php.wasm.zend_extension_statement_handler (wasm://wasm/php.wasm-08a18d7a:wasm-function[9230]:0x77b902)
      at php.wasm.zend_llist_apply_with_argument (wasm://wasm/php.wasm-08a18d7a:wasm-function[10088]:0x7ee577)
      at php.wasm.ZEND_EXT_STMT_SPEC_HANDLER (wasm://wasm/php.wasm-08a18d7a:wasm-function[9229]:0x77b8df)
}
node:internal/process/promises:394
    triggerUncaughtException(err, true /* fromPromise */);
    ^

Error: resolved is not a function
    at runExecutionFunction (file:///Users/cloudnik/www/Automattic/core/plugins/playground/packages/php-wasm/universal/src/lib/php.ts:971:22) {
  cause: TypeError: resolved is not a function
      at stubs.<computed> (file:///Users/cloudnik/www/Automattic/core/plugins/playground/packages/php-wasm/node/jspi/php_8_4.js:1296:15)
      at wasm://wasm/000ef1e6:wasm-function[545]:0x203cc
      at wasm://wasm/000ef1e6:wasm-function[604]:0x26320
      at wasm://wasm/000ef1e6:wasm-function[574]:0x228d0
      at wasm://wasm/000ef1e6:wasm-function[578]:0x232ca
      at wasm://wasm/000ef1e6:wasm-function[549]:0x20966
      at wasm://wasm/000ef1e6:wasm-function[219]:0xa209
      at php.wasm.zend_extension_statement_handler (wasm://wasm/php.wasm-08a18d7a:wasm-function[9230]:0x77b902)
      at php.wasm.zend_llist_apply_with_argument (wasm://wasm/php.wasm-08a18d7a:wasm-function[10088]:0x7ee577)
      at php.wasm.ZEND_EXT_STMT_SPEC_HANDLER (wasm://wasm/php.wasm-08a18d7a:wasm-function[9229]:0x77b8df)
}

Node.js v23.11.0

cc @mho22 @brandonpayton @akirk @wojtekn @griffbrad @bgrgicak

@adamziel adamziel marked this pull request as draft June 19, 2025 00:00
@adamziel adamziel changed the title XDebug <-> CDP Bridge Debug PHP in Browser's Devtools (XDebug <-> CDP Bridge) Jun 19, 2025
@adamziel adamziel changed the title Debug PHP in Browser's Devtools (XDebug <-> CDP Bridge) Debug PHP in browser Devtools (XDebug <-> CDP Bridge) Jun 19, 2025
@mho22
Copy link
Collaborator

mho22 commented Jun 19, 2025

@adamziel I'm impressed. A great way to begin my day. I need to dive deeper into that protocol.

@brandonpayton
Copy link
Member

@adamziel, this looks awesome!

@adamziel
Copy link
Collaborator Author

adamziel commented Jun 24, 2025

Or should we do WebDriver BiDi instead? Firefox is retiring its CDP support:

https://fxdx.dev/cdp-retirement-in-firefox/

And if you are migrating a tool from CDP to WebDriver BiDi for Firefox, you should also consider using WebDriver BiDi for Chromium based browsers. Chromium has a great support for WebDriver BiDi, and WebKit is starting to implement BiDi as well. So switching to BiDi now is not only a way to keep Firefox support, but it can also pave the way to get more features for all browsers as we keep expanding the standard protocol.

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

Successfully merging this pull request may close these issues.

3 participants