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

No output in devtools extension when using dump() #631

Open
FeBe95 opened this issue Apr 24, 2023 · 3 comments
Open

No output in devtools extension when using dump() #631

FeBe95 opened this issue Apr 24, 2023 · 3 comments

Comments

@FeBe95
Copy link
Contributor

FeBe95 commented Apr 24, 2023

Description

Whenever I use a dump() statement in my PHP code, nothing is logged in the embedded clockwork console in my browser devtools panel. The web-interface in myapp.localhost/clockwork works perfectly fine though.

Using the network tab of my browser's devtools, I can see that the X-Clockwork headers and response cookies are missing whenever I am using a dump() call.

Example code

routes/web.php:

Route::get('test', "TestController@show");

app/Http/Controllers/TestController.php:

namespace App\Http\Controllers;

class TestController extends Controller {
    public function show(): string
    {
        dump("Output Test");
        return "Hello World!";
    }
}

Expected Result

Dumping data with dump() should not interfere with the logging behavior of the browser extension. The necessary data does get generated and saved, as it is available in the standalone web-interface.
I understand if it doesn't work with Laravel's dd() function, as this function call exit(1) and thus ends the PHP process directly.

Is there something I need to configure in Laravel or Clockwork to get this working?

Actual Result

Browser:

grafik

Browser Extension (DevTools Panel):

grafik

Web-Interface:

grafik

@itsgoingd
Copy link
Owner

Hey, thanks for the detailed report.

Unfortunately I think this is a sort-of limitation of how dump works. Looks like dump immediately sends the output to the browser, this means headers are also sent at the point when you call dump.

Clockwork headers are set at the end of the request processing, but since at that point headers were already sent, this has no effect. The web UI still works, since it does not use the Clockwork headers at all and instead polls the Clockwork api for new requests.

@FeBe95
Copy link
Contributor Author

FeBe95 commented Jun 2, 2023

Hello and thanks for your reply. Would it technically be possible to set the necessary clockwork headers at the start of each request, so a dump() call wouldn't interfere with them?

@itsgoingd
Copy link
Owner

Yeah, it is technically possible, there is no nice Laravel way to set the headers at the right time, but you could just use the underlying header php function at the start of a global middleware:

header('X-Clockwork-Id: ' . $this->app['clockwork']->request()->id);
header('X-Clockwork-Version: ' . \Clockwork\Clockwork::VERSION);

I don't think this is something we want to do in Clockwork though.

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

No branches or pull requests

2 participants