Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Pfeil opened this issue Sep 22, 2023 · 1 comment
Open

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

Pfeil opened this issue Sep 22, 2023 · 1 comment

Comments

@Pfeil
Copy link

Pfeil commented Sep 22, 2023

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 #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
Copy link
Member

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:

  • The playground uses a custom documentLoader option, which has special handling for http://schema.org/ to rewrite it to https to avoid browser security restrictions.
  • If you want to handle requests yourself, and do any special header processing, you'll need to use (or modify) a documentLoader.
  • The HTML doc works when loaded from a test http server (python3 -m http.server). If you loaded from a https server you would need to use a documentLoader to handle the http URLs as https or similar such fixes.)
  • In both cases, when loading http[s]://schema.org/, they use a Link header to get processors to load JSON-LD:
    • link: </docs/jsonldcontext.jsonld>; rel="alternate"; type="application/ld+json"
  • In my network traffic on both cases, I see the schema.org request and then the load of the link header URL. (Though maybe with some internal browser caching related changes.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants