aboutsummaryrefslogtreecommitdiffstats
path: root/test/e2e/blossom-real.spec.ts
blob: a2feff82ff0e359b2fba7156e1af77644ad7b642 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { test, expect } from "@playwright/test";

const BLOSSOM_URL =
  "https://blossom.primal.net/7a2fd4e46f5054fa102c4db68f58c57e630c4f7fdfa06fa08a4b81b21741c541";

test("diagnose blossom image loading", async ({ page }) => {
  await page.goto("/");
  await page.waitForLoadState("domcontentloaded");

  const result = await page.evaluate(async (url) => {
    const diag: any = {};

    // Step 1: Fetch
    try {
      const r = await fetch(url);
      diag.fetchOk = r.ok;
      diag.fetchStatus = r.status;
      diag.fetchContentType = r.headers.get("content-type");
      diag.fetchUrl = r.url; // final URL after redirects

      const blob = await r.blob();
      diag.blobSize = blob.size;
      diag.blobType = blob.type;

      // Check first bytes (JPEG magic: FF D8 FF)
      const arr = new Uint8Array(await blob.slice(0, 4).arrayBuffer());
      diag.magic = Array.from(arr).map((b) => b.toString(16).padStart(2, "0")).join(" ");
      diag.isJpeg = arr[0] === 0xff && arr[1] === 0xd8 && arr[2] === 0xff;

      // Step 2: Re-type blob
      const retyped = new Blob([blob], { type: "image/jpeg" });
      diag.retypedSize = retyped.size;
      diag.retypedType = retyped.type;

      const blobUrl = URL.createObjectURL(retyped);
      diag.blobUrl = blobUrl;

      // Step 3: Try to load as img
      const img = document.createElement("img");
      img.src = blobUrl;
      document.body.prepend(img);

      const imgResult = await new Promise<string>((resolve) => {
        img.onload = () => resolve("loaded");
        img.onerror = () => resolve("error");
        setTimeout(() => resolve("timeout"), 10000);
      });

      diag.imgResult = imgResult;
      diag.naturalWidth = img.naturalWidth;
      diag.naturalHeight = img.naturalHeight;

      // Step 4: Also try data URL
      const reader = new FileReader();
      const dataUrl = await new Promise<string>((resolve) => {
        reader.onload = () => resolve(reader.result as string);
        reader.readAsDataURL(retyped);
      });
      diag.dataUrlPrefix = dataUrl.substring(0, 40);

      const img2 = document.createElement("img");
      img2.src = dataUrl;
      document.body.prepend(img2);

      const img2Result = await new Promise<string>((resolve) => {
        img2.onload = () => resolve("loaded");
        img2.onerror = () => resolve("error");
        setTimeout(() => resolve("timeout"), 10000);
      });
      diag.dataUrlResult = img2Result;
      diag.dataUrlWidth = img2.naturalWidth;
    } catch (e: any) {
      diag.error = e.message;
    }

    return diag;
  }, BLOSSOM_URL);

  console.log("Blossom diagnosis:", JSON.stringify(result, null, 2));
  // Just log, don't assert
});