-
Notifications
You must be signed in to change notification settings - Fork 108
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
Raw response for Optimization Detective storage request failure could be displayed in IFRAME
with srcdoc
instead of as raw HTML in PRE
#1828
Comments
@westonruter I am not able to generate the raw response mentioned in the ticket. Am I missing anything ? |
@SohamPatel46 yeah, you won't be able to using wp-env since loopback requests don't work. In wp-env only a |
See this relevant test case: performance/plugins/optimization-detective/tests/test-site-health.php Lines 117 to 128 in d94977f
The test case there should have included:
But that can be added in the next PR related to this. Here is a plugin you can use to emulate this: <?php
/**
* Plugin Name: Simulate REST API Blocked by Web Server
*/
add_filter(
'pre_http_request',
static function ( $pre, $args, $url ) {
if ( ! str_starts_with( $url, rest_url() ) ) {
return $pre;
}
return array(
'response' => array(
'code' => 403,
'message' => 'Forbidden',
),
'headers' => array(
'content-type' => 'text/html',
),
'body' => "<html>\n<head><title>403 Forbidden</title></head>\n<body>\n<center><h1>403 Forbidden</h1></center>\n<hr><center>nginx</center>\n</body>\n</html>",
);
},
10,
3
); This is what that results in on the Site Health screen: |
@westonruter The warning displayed is rendered using To avoid this issue, we need to whitelist iframes to be allowed in Let me know if this is a good idea to implement and whitelisting iframes is safe. |
I see that (Sorry, I accidentally submitted this comment prematurely.) |
Feature Description
When the storage endpoint for Optimization Detective is not accessible (see #1762), an error notice is displayed:
When expanding the raw response, this can can result in an HTML page being shown in code:
It would be preferable if this were presented more nicely, such as in an
IFRAME
viasrcdoc
(withsandbox
), like so:This should be straightforward to do simply by checking if the cached response has a
text/html
type, and if so, present in anIFRAME
instead of as aPRE
tag.The text was updated successfully, but these errors were encountered: