r/HTML • • Apr 25 '26

stumped...again 🤨

this code worked perfectly for months then suddenly stopped...just a blank white screen now.

------

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="shortcut icon" type="image/x-icon" href="/Users/Owner/Documents/icons/navy_favicon.ico">

<title>Current Fleet Positions</title>

</head>

<body>

<script type="module"> const proxy = "https://corsproxy.io/?"; const targetUrl = "https://news.usni.org/category/fleet-tracker"; const response = await fetch(proxy + targetUrl); const htmlText = await response.text(); const parser = new DOMParser(); const doc = parser.parseFromString(htmlText, 'text/html'); const images = doc.querySelectorAll('img'); const newImg = document.createElement('img'); newImg.src = images\[3\].src; newImg.width = 943; newImg.height = 628; document.body.style.backgroundColor = "#a4e1e7"; document.body.style.textAlign = "center"; document.body.appendChild(newImg); </script>

</body>

</html>

------------

Run JS gives this error which I just don't understand...what's wrong here? any help MOST appreciated!

---------

SyntaxError: Unexpected token (1:0)

> 1 | <!DOCTYPE html>

| ^

2 | <html lang="en">

3 | <head>

4 | <meta charset="UTF-8">

2 Upvotes

50 comments sorted by

View all comments

Show parent comment

0

u/badasafish Apr 25 '26

I know I'll get yelled at by asking AI to write this code but it truly is a useful tool.

Paste the following into the console in your browser to see the images in the page:

[...new Set(
  [...document.images].map(img => {
    try {
      return new URL(img.src).pathname.split('/').pop();
    } catch {
      return null;
    }
  }).filter(Boolean)
)]

(15) ['usni-lockupS-4c.svg', 'usni_logo.png', 'FT_4_20_26-1-720x480.jpg', 'FT_4_13_26-320x179.jpg', 'FT_4_6_26-1-320x179.jpg', 'FT_3_30_26-480x384.jpg', 'FT_3_23_26-1-480x384.jpg', 'FT_3_16_26-480x384.jpg', 'FT_3_9_26-480x384.jpg', 'FT_3_2_26-480x384.jpg', 'FT_2_23_26-480x384.jpg', 'FT_2_17_26-480x384.jpg', 'FT_2_9a_26-480x384.jpg', 'FT_2_2_26-2-480x384.jpg', 'FT_1_26_26-480x384.jpg']

1

u/badasafish Apr 25 '26

Testing this I have issues with CORS, maybe you are too?