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

Use console.context() for logging in Optimization Detective and export console logging functions to extensions #1886

Open
westonruter opened this issue Feb 26, 2025 · 1 comment
Labels
[Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Enhancement A suggestion for improvement of an existing feature

Comments

@westonruter
Copy link
Member

I just learned about console.context() via https://devtoolstips.org/tips/en/create-contextual-console-loggers/

This can be used to filter messages by the context via the context: operator in the filter search box.

We could create info, warn, and log, error functions which we expose to the client-side extensions' initialize() and finalize() functions as well. Maybe these functions could automatically take into account the value of isDebug coming from WP_DEBUG in PHP, so that they automatically no-op when called. That would avoid the need to wrap calls in if ( isDebug ) { ... } all the time in extensions.

@westonruter westonruter added [Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Enhancement A suggestion for improvement of an existing feature labels Feb 26, 2025
@github-project-automation github-project-automation bot moved this to Not Started/Backlog 📆 in WP Performance 2025 Feb 26, 2025
@ShyamGadde
Copy link
Contributor

I noticed that console.context() is currently "an experiment in Chromium-based browsers only" according to the article you linked. This might cause errors in Firefox, Safari, and other non-Chromium browsers.

Would it make sense to implement simple feature detection before using it? Maybe something like:

function createLogger(...) {
    ...
    if (typeof console.context === 'function') {
        // Use console.context
    } else {
        // Fall back to regular console with prefixed messages
    }
    ...
}

This way we could still benefit from context in supported browsers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Enhancement A suggestion for improvement of an existing feature
Projects
Status: Not Started/Backlog 📆
Development

No branches or pull requests

2 participants