Why an Image URL Opens in a Tab but Not on Your Website

Find out why an image URL opens in a browser but not on your website, and troubleshoot CORS, hotlink protection, authentication, and image responses.

Published
Reading time
7 min read
Why an Image URL Opens in a Tab but Not on Your Website
On this page

If an image URL opens in your browser but not on your website, the URL may be reachable while the embedded request is blocked, rejected, or returning something other than an image. A request made by an <img> element can differ from a top-level navigation in its headers, credentials, and browser security rules.

This guide shows how to inspect the embedded request and distinguish CORS errors from hotlink protection, authentication failures, and invalid image responses. The example has not been executed here. The MDN documentation for the HTML img element and CORS could not be consulted in this environment, so check it when confirming browser-specific behavior.

Key Takeaways

  • Opening a URL in a tab proves that one navigation succeeded; it does not prove that another page can embed the response.
  • Inspect the image request made by the page, including its status, redirects, response headers, and console errors.
  • A normal cross-origin <img> can often display without CORS permission. CORS becomes relevant when the image is requested in CORS mode or its pixels are accessed through a canvas.
  • Hotlink protection and authentication are server-side decisions, while CORS, content security policy, and mixed-content restrictions involve browser enforcement.
  • An HTTP status check alone cannot establish that an image will render.

Why the same URL can behave differently

When you paste an image URL into a tab, the browser makes a navigation request. When a page embeds that URL, the browser makes an image request in the context of that page. Those requests can differ in their referrer, cookies, other headers, and applicable security policies.

For example, an image host might allow direct navigation but reject requests whose Referer identifies another website. Or a navigation might carry a login cookie that is unavailable to the embedded request. Neither outcome proves a CORS problem.

Advertisement

Reproduce the embedded request

Use a real HTTPS image URL that you own or are authorized to test. Save the following as image-test.html, replacing the example URL with that address:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Image embed test</title>
</head>
<body>
  <img src="https://images.example.com/photo.jpg" alt="Embed test image">
</body>
</html>

Serve the file from a local development server rather than opening it as a file: URL. For example, if Python is installed, run this command in the directory containing the file:

python3 -m http.server 8000

Open http://localhost:8000/image-test.html, then:

  1. Open browser developer tools and select the Network panel. Reload the page with the panel open.
  2. Select the image request. If necessary, filter by image or search for part of the URL.
  3. Inspect the status and any redirects. Check the final response's Content-Type, and preview the response if developer tools permits it.
  4. Compare the request headers, especially Referer, with those of a successful navigation. Check whether cookies are being sent without copying their values into tickets or logs.
  5. Open the Console and look for messages about CORS, content security policy, mixed content, or blocked resources.
  6. Repeat on the actual page where the failure occurs. The local test has a different origin and may have different policies and credentials.

A 200 response is not enough: a server can return a login page, an error document, or unusable bytes with that status. Likewise, a redirect can lead to a different host or response than the original URL suggests. An HTTP status checker can help identify a status or redirect, but it cannot reproduce every browser request context or prove that the image will display.

Interpret the evidence

CORS: display is not the same as pixel access

A plain <img src="…"> does not generally need the image server to grant CORS permission merely to display a cross-origin image. However, a browser can still block it for other reasons, including site policy or the image server's response.

CORS matters when you explicitly request the image in CORS mode with crossorigin, or when you need to use image pixels in a canvas. Drawing a cross-origin image without suitable CORS permission can taint the canvas, preventing pixel readback or export.

If you need canvas access, the image host must cooperate. For a public image, the markup might be:

<img
  src="https://images.example.com/photo.jpg"
  crossorigin="anonymous"
  alt="Example image"
>

The server must return an appropriate Access-Control-Allow-Origin header for the requesting page. Adding crossorigin alone does not grant permission and can cause an image that previously displayed to fail if the server does not provide a suitable CORS response. Credentialed CORS requests require additional server cooperation; a wildcard origin is not sufficient for a credentialed response.

An image host may restrict embedding from other sites, often using the request's Referer or other request context. A direct navigation can therefore succeed while the embedded request receives a 403, a redirect, or a replacement response.

Inspect the image request and ask the image provider which embedding arrangements are permitted. If you control the host, configure an appropriate policy for the sites you authorize. Do not assume that a missing or altered referrer proves hotlinking: referrer policies and privacy settings can affect what the browser sends.

Authentication: the embedded request lacks access

A protected image may open in a tab when you are signed in but fail when embedded because the server does not receive the required credentials. Cookie scope, SameSite rules, and browser privacy settings can affect whether cookies are sent in an embedded context. A server might return 401 or 403, or redirect to a login page that ultimately returns 200 with HTML.

Check the redirect chain and response content. If embedding is intended, use an access mechanism supported by the image provider, such as an appropriately scoped public asset or an authorized delivery arrangement. Treat signed URLs as secrets when they grant access, and avoid posting them in public debugging reports.

Advertisement

Invalid response: the URL did not return a usable image

Check whether the final response actually contains a decodable image. An HTML error page, expired signed URL, truncated file, unsupported format, or incorrect Content-Type can prevent rendering. The precise effect of an incorrect type can depend on the browser and response headers, so inspect both the headers and the response rather than inferring the cause from one field.

If the image loads successfully in the network panel but is not visible, inspect the page layout too: CSS can hide the element, give it zero dimensions, or place it behind another element. The element's naturalWidth in developer tools can help distinguish a decoded image from one that did not load.

Check browser policies on the embedding page

  • Content Security Policy: An img-src directive can restrict which image origins the page may load. Check the console and the policy delivered with the embedding page; update it only for hosts the application trusts.
  • Mixed content: An HTTPS page embedding an HTTP image can encounter browser mixed-content handling. Prefer an HTTPS image URL and inspect the console and network panel for what happened in the browser being tested.
  • Other resource policies: Cross-origin resource policy headers or other browser protections may block a response. Use the browser's reported error and response headers to investigate rather than assuming every block is CORS.
  • Extensions and local settings: If the request appears blocked only in one browser profile, compare with a clean profile, subject to your organization's testing rules.

Common Mistakes

  • Adding CORS headers to the embedding page. CORS permission for an image response comes from the image server, not from a header added solely to the page displaying it.
  • Treating every 403 as CORS. It may be an authorization or hotlink decision. Inspect the request and server behavior.
  • Trusting the final status without checking the body. A successful login-page response is not a successful image response.
  • Testing only by pasting the URL into a tab. Capture the request made by the actual failing page.
  • Assuming a local reproduction has the same origin and policies as production. Compare both environments.

Best Practices

Use images from hosts that explicitly permit your intended embedding and access pattern. If you control the asset, serve a valid image over HTTPS with the correct content type and configure only the policies your application needs. For protected assets, design authorization deliberately rather than relying on a URL remaining obscure.

When reporting a failure, include the page origin, image host, status and redirect chain, relevant response headers, and browser console message. Redact cookies, tokens, and signed URL parameters. Recheck the result in the target browser after changing server or page configuration.

Conclusion

Start with the embedded request, not the URL opened in a separate tab. Its response, redirects, request context, and browser errors usually reveal whether the next step belongs with the image host, authentication setup, page policy, or the image file itself.

What would your domain sell for?

A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.