Skip to content

Instantly share code, notes, and snippets.

@NatElkins
Created April 3, 2025 17:52
Show Gist options
  • Select an option

  • Save NatElkins/6f2538e58778fdf2868419d8248e10a1 to your computer and use it in GitHub Desktop.

Select an option

Save NatElkins/6f2538e58778fdf2868419d8248e10a1 to your computer and use it in GitHub Desktop.

Revisions

  1. NatElkins created this gist Apr 3, 2025.
    46 changes: 46 additions & 0 deletions browser_test.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    <!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>
    42 changes: 42 additions & 0 deletions test_server.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    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()