Skip to content

Instantly share code, notes, and snippets.

View westonruter's full-sized avatar

Weston Ruter westonruter

View GitHub Profile
# HTTP Archive query for how often the mediaelement-core script is on a WordPress page.
#
# WPP Research, Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
@westonruter
westonruter / js-self-profile.mjs
Created April 8, 2024 21:05
POC for how to hack Puppeteer to be able to use the JS Self-Profiling API
// Usage: node js-self-profile.mjs https://example.com/
import puppeteer from 'puppeteer';
import http from 'http';
import https from 'https';
const PROXY_SERVER_PORT = 8080;
// Create an HTTP server so that we can inject the Document-Policy header in the response. Otherwise, the JS Self-Profiling API is not available.
const server = http.createServer(async (req, res) => {
jQuery( function ( $ ) {
const blockMainThread = function ( ms ) {
console.info( `blocking for ${ms} ms.` );
const startTime = performance.now();
while ( performance.now() - startTime < ms ) {
continue;
}
};
@westonruter
westonruter / class-grouped-numbers.php
Last active February 23, 2024 01:43
Test case to demonstrate erroneous static analysis in PhpStorm
<?php declare(strict_types = 1);
final class Grouped_Numbers {
/**
* Grouped numbers.
*
* @var array<string, int[]>
*/
private $grouped_numbers;
<?php
/**
* Plugin Name: Admin PWA
* Plugin URI: https://github.com/GoogleChromeLabs/pwa-wp/issues/295
* Description: Proof of concept to turn the WordPress admin into a PWA.
* Version: 0.1.0
* Author: Weston Ruter
* Author URI: https://weston.ruter.net/
* Text Domain: pwa
* License: GPL-2.0+
diff --git a/src/wp-includes/class-wp-block-type.php b/src/wp-includes/class-wp-block-type.php
index 33825a7888..d31aaf0b69 100644
--- a/src/wp-includes/class-wp-block-type.php
+++ b/src/wp-includes/class-wp-block-type.php
@@ -11,6 +11,7 @@
* Core class representing a block type.
*
* @since 5.0.0
+ * @property array[] $variations Block variations.
*
<?php
/**
* Vary LCP Image Optimizations WordPress Plugin.
*
* @package VaryLcpImageOptimizations
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2023 Google Inc.
*
* @wordpress-plugin
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="https://glitch.com/favicon.ico" />
<title>image-with-fetchpriority-and-with-preload.html</title>
<link
<!-- wp:group {"style":{"background":{"backgroundImage":{"url":"http://localhost:8889/wp-content/uploads/2023/09/image.jpeg","id":112,"source":"file","title":"image"}},"spacing":{"padding":{"right":"var:preset|spacing|30","left":"var:preset|spacing|30"}}},"backgroundColor":"contrast","layout":{"type":"constrained","justifyContent":"right"}} -->
<div class="wp-block-group has-contrast-background-color has-background" style="padding-right:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--30)"><!-- wp:spacer {"height":"284px"} -->
<div style="height:284px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:paragraph {"align":"right","style":{"elements":{"link":{"color":{"text":"var:preset|color|base"}}}},"textColor":"base"} -->
<p class="has-text-align-right has-base-color has-text-color has-link-color">No <code>fetchpriority</code> for<br><code>background-image</code> here<br>yet it is the LCP element.</p>
<!-- /wp:paragraph -->
<!-- wp:spacer {"height":"161px"}
<?php
/**
* Contact Form 7 Conditional Enqueues WordPress Plugin.
*
* @package CF7_Conditional_Enqueues
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2023 Google Inc.
*
* @wordpress-plugin