digitalbazaar / jsonld.js

A JSON-LD Processor and API implementation in JavaScript
https://json-ld.org/
Other
1.64k stars 195 forks source link

CORS issue with schema.org, with minimal example #538

Open Pfeil opened 9 months ago

Pfeil commented 9 months ago

Hi, not sure what I am doing wrong; isn't this example (representing this one) supposed to work? It also happens with compact and probably also other algorithms. Flatten works for me. Is this access really needed? How does the playground avoid it? The playground seems to use version 8.3.1, so is this example. Is there a configuration option I missed? I tried them without success so far. I also do not quite understand their meaning in every case. Furthermore, I also tried to set the Origin request header (attached below) manually without success so far, but I wouldn't know how to ask jsonld.js to set it in any case.

(probably related to https://github.com/digitalbazaar/jsonld.js/issues/451 somehow?)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JSON-LD Test</title>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jsonld@8.3.1/dist/jsonld.min.js"></script>
</head>
<body>
    <script>
        jsonld.frame(
            {
                "@context": "http://schema.org/",
                "@type": "Person",
                "name": "Jane Doe",
                "jobTitle": "Professor",
                "telephone": "(425) 123-4567",
                "url": "http://www.janedoe.com"
            },
            {
                "@context": "http://schema.org/"
            }
        )
    </script>
</body>
</html>

Resulting request headers:

GET / HTTP/1.1
Host: schema.org
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/117.0
Accept: application/ld+json, application/json
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Origin: null
DNT: 1
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

Resulting response headers:

HTTP/1.1 301 Moved Permanently
Location: https://schema.org/
X-Cloud-Trace-Context: 388f6ce932f84b073dc587fdbf6d86f2
Date: Fri, 22 Sep 2023 10:27:37 GMT
Content-Type: text/html
Server: Google Frontend
Content-Length: 0

No response body.

davidlehn commented 9 months ago

The playground and HTML examples work for me. Will need more details on what's not working to help.

As far as how they work: