Whats up — macOS Sonoma / iOS developer right here. I’m attempting to fetch a end result web page for testing however my app (and Safari) both hangs or returns nil response whereas Chrome/Firefox load it wonderful.
Take a look at URL I’m checking:
I hooked up two minimal reproductions beneath (one Swift for my macOS/iOS app, one plain JS for the browser). Each have intentional errors — I wish to see what skilled devs will level out and whether or not this website behaves otherwise for sure requests (CORS, TLS, UA blocking, or anti-bot). Please check the precise URL and clarify the foundation trigger.
import Basis
func fetchResults() {
// 1) Utilizing a "protected" URL however deliberately doing flawed parse
let uncooked = "https://star49s.com"
let url = URL(string: uncooked)! // BUG: drive unwrap with out guard
var req = URLRequest(url: url)
req.httpMethod = "GET"
req.addValue("software/json", forHTTPHeaderField: "Settle for") // website returns HTML, not JSON
let process = URLSession.shared.dataTask(with: req) { information, resp, err in
if err != nil {
print("Community error:", err) // okay
return
}
// BUG: not checking HTTPURLResponse statusCode
// BUG: assuming JSON response for HTML web page
do {
let json = attempt JSONSerialization.jsonObject(with: information!, choices: []) // drive unwrap
print("Parsed JSON:", json)
} catch {
print("Parse error (anticipated):", error)
}
}
// BUG: forgot to begin the duty
// process.resume()
}
fetchResults()
Take a look at force-unwrapping, lacking resume(), flawed settle for header, and assuming JSON.
Additionally attempt working whereas related to ProtonVPN or totally different community to check conduct.
JavaScript (browser) — reproducer with CORS-ish downside
// Minimal fetch within the console or extension context
(async () => {
attempt {
// BUG: utilizing no-cors hides response physique in browser
const res = await fetch("https://star49s.com", {
technique: "GET",
mode: "no-cors", // this may produce an opaque response that .textual content() cannot learn
headers: {
"ContentType": "textual content/html" // BUG: header identify typo (needs to be Content material-Kind)
}
});
const txt = await res.textual content(); // for opaque responses this may throw or return empty
console.log("size:", txt.size);
console.log(txt.slice(0, 200));
} catch (e) {
console.error("Fetch failed:", e);
}
})();
Attempt eradicating mode: “no-cors” and check in Safari/Chrome to see CORS headers.
Test community tab for blocked preflight or 403/429 responses.
Additionally check with totally different Person-Agent (Safari UA vs Chrome UA) and with a browser extension disabled.
I Need from solutions
Which of the above bugs would trigger a grasp / empty response in Safari vs Chrome?
May the positioning be blocking sure request headers / UAs or require TLS settings?
Finest steps to reliably debug this on macOS (Console.app, tcpdump, or Safari devtools)?
Any fast code fixes so my Swift/JS can robustly detect and report the true HTTP standing and physique?
Thanks prematurely — please check the precise URL: https://star49s.com and point out what you see (standing code, headers, and whether or not the physique is HTML or empty).
