From b3a9cf2c64ac4fbf79686cd9e7e5662250d7e4ba Mon Sep 17 00:00:00 2001 From: Scott Jehl Date: Thu, 12 Jan 2023 21:39:43 +0000 Subject: [PATCH] initial functional pass at a edit html response body experiment. #2471 --- www/assets/css/pagestyle2.css | 13 +++++++++++++ www/experiments.php | 6 ++++-- www/experiments/custom.inc | 24 ++++++++++++++++++++++++ www/experiments/getExperimentHTML.php | 19 +++++++++++++++++++ www/runtest.php | 6 +++++- 5 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 www/experiments/getExperimentHTML.php diff --git a/www/assets/css/pagestyle2.css b/www/assets/css/pagestyle2.css index 49ac43162e..7373ee405f 100644 --- a/www/assets/css/pagestyle2.css +++ b/www/assets/css/pagestyle2.css @@ -885,6 +885,7 @@ h4.experiments_list_hed-recs { } .experiments_list > li:target { background: #f8f7e0; + scroll-padding-top: 4rem; } .experiment_description code { @@ -2211,6 +2212,18 @@ footer ul { } } +.experiment_description_go > label.experiment_pair_value textarea[data-fullscreenfocus=true]:focus { + position: fixed; + top: 10vh; + left: 10vw; + right: 10vw; + bottom: 10vh; + z-index: 999999; + box-shadow: 0 0 0 11vw rgba(0,0,0,.3); + height: 80vh; + width: 80vw; +} + @media (max-width: 50em) { .grade_header, .experiments_foot { diff --git a/www/experiments.php b/www/experiments.php index 386e63bcfe..d13126c887 100644 --- a/www/experiments.php +++ b/www/experiments.php @@ -349,11 +349,13 @@ function observationHTML($parts) } elseif ($exp->expvar && !$exp->expval && $textinput) { if ($experimentEnabled) { $placeholderEncodedVal = htmlentities(''); + $textinputvalue = $exp->textinputvalue ? $exp->textinputvalue : ""; + $fullscreenfocus = $exp->fullscreenfocus ? "true" : "false"; $out .= <<
- +
EOT; @@ -582,7 +584,7 @@ function refreshExperimentFormState(){ } } } - if( input && !(keyval[1] === 'on' && form.querySelectorAll("[type=checkbox][name='" + keyval[0] + "']")) ){ + if( input && !(keyval[1] === 'on' && form.querySelectorAll("[type=checkbox][name='" + keyval[0] + "']")) && keyval[1] !== "" ){ input.value = keyval[1]; input.setAttribute('data-hydrated', 'true'); } diff --git a/www/experiments/custom.inc b/www/experiments/custom.inc index e431f452aa..315c9c437f 100644 --- a/www/experiments/custom.inc +++ b/www/experiments/custom.inc @@ -1,5 +1,9 @@ getRequests(); + $category = "Custom"; $assessment[$category]["opportunities"][] = array( "title" => "Add HTML to document", @@ -68,6 +72,26 @@ $assessment[$category]["opportunities"][] = array( "inputttext" => true ); +if( $requests[0]['body_url'] ){ + $assessment[$category]["opportunities"][] = array( + "title" => "Edit Response HTML", + "desc" => "This experiment allows you to freely edit the text of the initial HTML response", + "examples" => array(), + "experiments" => array( + (object) [ + 'id' => '054', + 'title' => 'Edit Response HTML', + "desc" => '

This experiment will replace the initial HTML with the submitted value as if it was served that way initially.

', + "expvar" => 'editresponsehtml', + 'textinputvalue' => htmlentities(file_get_contents("https://next.webpagetest.org" . $requests[0]['body_url'])), + "fullscreenfocus" => true + ] + ), + "good" => null, + "inputttext" => true + ); +} + $assessment[$category]["opportunities"][] = array( "title" => "Delivery Optimizations", diff --git a/www/experiments/getExperimentHTML.php b/www/experiments/getExperimentHTML.php new file mode 100644 index 0000000000..876ea8537c --- /dev/null +++ b/www/experiments/getExperimentHTML.php @@ -0,0 +1,19 @@ +metadata){ + $recipes = json_decode($testInfo->metadata)->experiment->recipes; + $html = ""; + + foreach($recipes as $recipe){ + if( $recipe->{'054'} ){ + $html = $recipe->{'054'}[0]; + } + + } +} + +echo $html; \ No newline at end of file diff --git a/www/runtest.php b/www/runtest.php index 02c945bfa6..073af8b7b7 100644 --- a/www/runtest.php +++ b/www/runtest.php @@ -1021,6 +1021,10 @@ function buildSelfHost($hosts) } $ingredients = implode(",", $ingredients); } + if($recipeSansId === "editresponsehtml"){ + // striking out the ingredients here because it's too much to send in a cookie + $ingredients = ""; + } // these recipes need encoded values. they all do afterwards! TODO if ( $recipeSansId === "insertheadstart" @@ -1109,7 +1113,7 @@ function buildSelfHost($hosts) //replace last step with last step plus recipes - $test['script'] = str_replace($scriptNavigate, "setCookie\t" . $originToUse . "\twpt-experiments=" . urlencode($recipeScript) . "\r\n" . $scriptNavigate, $test['script']); + $test['script'] = str_replace($scriptNavigate, "setCookie\t" . $originToUse . "\twpt-experiments=" . urlencode($recipeScript) . "\r\n" . "setCookie\t" . $originToUse . "\twpt-testid=" . urlencode($id) . "\r\n" . $scriptNavigate, $test['script']); $id = CreateTest($test, $test['url']);