* Opts in to / out of the pre-release channels or a specific RTV by setting the * __Host-AMP_OPT_IN cookie. * @param {string} cookieState One of the AMP_OPT_IN_COOKIE enum values, or a * 15-digit RTV.
(cookieState)
| 279 | * 15-digit RTV. |
| 280 | */ |
| 281 | function setAmpOptInCookie_(cookieState) { |
| 282 | let validUntil = 0; |
| 283 | if (RTV_PATTERN.test(cookieState)) { |
| 284 | validUntil = Date.now() + RTV_COOKIE_MAX_AGE_MS; |
| 285 | } else if (cookieState != AMP_OPT_IN_COOKIE.DISABLED) { |
| 286 | validUntil = Date.now() + COOKIE_MAX_AGE_MS; |
| 287 | } |
| 288 | const cookieOptions = { |
| 289 | allowOnProxyOrigin: true, |
| 290 | // Make sure the cookie is available for the script loads coming from |
| 291 | // other domains. Chrome's default of LAX would otherwise prevent it |
| 292 | // from being sent. |
| 293 | sameSite: SameSite_Enum.NONE, |
| 294 | secure: true, |
| 295 | }; |
| 296 | setCookie( |
| 297 | window, |
| 298 | '__Host-AMP_OPT_IN', |
| 299 | cookieState, |
| 300 | validUntil, |
| 301 | cookieOptions |
| 302 | ); |
| 303 | // Reflect default experiment state. |
| 304 | self.location.reload(); |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Toggles the experiment. |
no test coverage detected