Skip to content

Instantly share code, notes, and snippets.

@NatElkins
Created April 3, 2025 17:52
Show Gist options
  • Save NatElkins/6f2538e58778fdf2868419d8248e10a1 to your computer and use it in GitHub Desktop.
Save NatElkins/6f2538e58778fdf2868419d8248e10a1 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Browser Performance Test</title>
<style>
.test-section {
margin: 20px;
padding: 20px;
border: 1px solid #ccc;
}
.loading-time {
color: #666;
font-size: 12px;
}
</style>
</head>
<body>
<div class="test-section">
<h2>Text Content</h2>
<p>This is a test paragraph with some text content.</p>
</div>
<div class="test-section">
<h2>Images</h2>
<img src="https://picsum.photos/400/300" alt="Random image 1">
<img src="https://picsum.photos/400/300" alt="Random image 2">
</div>
<div class="test-section">
<h2>JavaScript</h2>
<div id="js-test">JavaScript will update this text</div>
</div>
<script>
// Measure page load time
window.addEventListener('load', function() {
const loadTime = performance.now();
console.log('Page load time:', loadTime, 'ms');
// Update the JavaScript test div
document.getElementById('js-test').textContent =
'JavaScript executed. Page loaded in ' + loadTime.toFixed(2) + 'ms';
});
</script>
</body>
</html>
from http.server import HTTPServer, SimpleHTTPRequestHandler
import os
import subprocess
class TestHandler(SimpleHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.path = '/browser_test.html'
return SimpleHTTPRequestHandler.do_GET(self)
def open_chrome():
chrome_path = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
if os.path.exists(chrome_path):
subprocess.Popen([chrome_path, 'http://localhost:8000'])
else:
print("Chrome not found at default location")
def open_firefox():
firefox_path = '/Applications/Firefox.app/Contents/MacOS/firefox'
if os.path.exists(firefox_path):
subprocess.Popen([firefox_path, 'http://localhost:8000'])
else:
print("Firefox not found at default location")
def run_server():
server_address = ('', 8000)
httpd = HTTPServer(server_address, TestHandler)
print("Starting test server on http://localhost:8000")
print("Press Ctrl+C to stop the server")
# Feel free to comment out if you're not on a Mac
open_chrome()
open_firefox()
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nShutting down server")
httpd.server_close()
if __name__ == '__main__':
run_server()
@NatElkins
Copy link
Author

Just put these files side by side and run with python3 test_server.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment