Skip to content

Fetch: Cross-Origin Requests - #495

Open
diogoosz wants to merge 1 commit into
javascript-tutorial:masterfrom
diogoosz:translate-fetch-crossorigin
Open

diogoosz wants to merge 1 commit into
javascript-tutorial:masterfrom
diogoosz:translate-fetch-crossorigin

Conversation

@diogoosz

Copy link
Copy Markdown
Contributor

Resumo

  • Traduz o artigo "Fetch: Cross-Origin Requests" e seu exercício.
  • Traduz os dois diagramas SVG (xhr-another-domain.svg, xhr-preflight.svg) via images.yml + pipeline do gulp, conferidos visualmente.
  • Nomes de cabeçalhos/métodos HTTP (Origin, Access-Control-*, OPTIONS etc.) ficaram sem tradução, por serem identificadores de protocolo.

Plano de teste

  • Diff de todos os trechos de código (code spans) entre o original em inglês e a tradução.
  • Grep em busca de falsos cognatos conhecidos e registro informal.
  • Releitura manual completa para checar sentido e concordância.
  • Verificação visual dos dois SVGs traduzidos.

🤖 Generated with Claude Code

Translates the article, its exercise, and the two SVG diagrams
(xhr-another-domain.svg, xhr-preflight.svg) via images.yml + the
gulp translation pipeline, verified visually. HTTP header/method
names (Origin, Access-Control-*, OPTIONS, etc.) are kept untranslated
as they're protocol identifiers, not prose.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1. Why `Origin` is needed, if `Referer` has even more information?
2. Is it possible that there's no `Referer` or `Origin`, or is it incorrect?
1. Por que `Origin` é necessário, se `Referer` tem até mais informação?
2. É possível que não haja `Referer` ou `Origin`, ou isso está incorreto?

@gabifs gabifs Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A segunda pergunta mudou de sentido. O original ("Is it possible that there is no Referer or Origin, or is it incorrect?") pergunta se os cabeçalhos podem estar ausentes ou conter um valor errado. Já "ou isso está incorreto?" dá a entender "ou essa afirmação está incorreta?", o que não corresponde ao que a solução responde. Que tal assim?

Suggested change
2. É possível que não haja `Referer` ou `Origin`, ou isso está incorreto?
2. É possível que não haja `Referer` ou `Origin`, ou que eles estejam incorretos?

@@ -1,8 +1,8 @@
# Fetch: Cross-Origin Requests

@gabifs gabifs Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O título do artigo ficou em inglês, enquanto todo o corpo foi traduzido. Assim, o cabeçalho do capítulo e a entrada no sumário aparecem como "Fetch: Cross-Origin Requests". Os demais artigos traduzidos do repositório traduzem o título # (por exemplo, "# Estrutura do código", "# Variáveis"). Sugestão:

Suggested change
# Fetch: Cross-Origin Requests
# Fetch: Requisições Cross-Origin

Então, para evitar mal-entendidos, para qualquer requisição "insegura" -- que não podia ser feita nos tempos antigos, o navegador não faz esse tipo de requisição imediatamente. Primeiro, ele envia uma requisição preliminar, chamada de "preflight", para pedir permissão.

A preflight request uses the method `OPTIONS`, no body and three headers:
Uma requisição preflight usa o método `OPTIONS`, sem corpo e três cabeçalhos:

@gabifs gabifs Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pequeno ajuste (opcional): "sem corpo e três cabeçalhos" pode ser lido como "sem corpo e sem três cabeçalhos", porque o "sem" acaba se aplicando aos dois substantivos. O original diz que a requisição preflight não tem corpo, mas tem três cabeçalhos.

Suggested change
Uma requisição preflight usa o método `OPTIONS`, sem corpo e três cabeçalhos:
Uma requisição preflight usa o método `OPTIONS`, sem corpo e com três cabeçalhos:

@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="620" height="633" viewBox="0 0 620 633"><defs><style>@import url(https://fonts.googleapis.com/css?family=Open+Sans:bold,italic,bolditalic%7CPT+Mono);@font-face{font-family:&apos;PT Mono&apos;;font-weight:700;font-style:normal;src:local(&apos;PT MonoBold&apos;),url(/font/PTMonoBold.woff2) format(&apos;woff2&apos;),url(/font/PTMonoBold.woff) format(&apos;woff&apos;),url(/font/PTMonoBold.ttf) format(&apos;truetype&apos;)}</style></defs><g id="network" fill="none" fill-rule="evenodd" stroke="none" stroke-width="1"><g id="xhr-preflight.svg"><path id="Rectangle-227" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M1 16h128v64H1z"/><text id="JavaScript" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="33" y="50">JavaScript</tspan></text><path id="Rectangle-228" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M240 16h128v64H240z"/><text id="Browser" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="278" y="48">Browser</tspan></text><path id="Rectangle-229" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M491 16h128v64H491z"/><text id="Server" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="534" y="50">Server</tspan></text><path id="Line" stroke="#7E7C7B" stroke-linecap="square" d="M66 82v520M305 82v520M556 82v520"/><path id="Line" fill="#C06334" fill-rule="nonzero" d="M291 133l14 7-14 7-.001-6H67v-2h223.999l.001-6z"/><text id="fetch()" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="166" y="131">fetch()</tspan></text><text id="OPTIONS" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="400" y="173">OPTIONS</tspan></text><text id="Origin-Access-Contro" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="406.721" y="198">Origin</tspan> <tspan x="321.866" y="216">Access-Control-Request-Method</tspan> <tspan x="320" y="234">Access-Control-Request-Headers</tspan></text><path id="Line" fill="#C06334" fill-rule="nonzero" d="M319 285.5v6h237v2H319v6l-14-7 14-7z"/><text id="200-OK" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="407" y="285">200 OK</tspan></text><path id="Line-4" fill="#C06334" fill-rule="nonzero" d="M542 173l14 7-14 7-.001-6H305v-2h236.999l.001-6z"/><path id="Line-2" fill="#C06334" fill-rule="nonzero" d="M319 495v6h237v2H319v6l-14-7 14-7z"/><path id="Line-3" fill="#C06334" fill-rule="nonzero" d="M90.5 544.5v8h214v3h-214v8l-19-9.5 19-9.5z"/><text id="Access-Control-Allow" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="336" y="522">Access-Control-Allow-Origin</tspan></text><text id="Main-HTTP-response" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="355" y="495">Main HTTP-response</tspan></text><text id="otherwise-error" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="130" y="570">otherwise error</tspan></text><text id="if-allowed:-success," fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="115.5" y="545">if allowed: success,</tspan></text><path id="Line-5" fill="#C06334" fill-rule="nonzero" d="M542 429l14 7-14 7-.001-6H304v-2h237.999l.001-6z"/><text id="Origin" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="405" y="454">Origin</tspan></text><text id="Main-HTTP-request" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="360" y="429">Main HTTP-request</tspan></text><text id="preflight" fill="#7E7C7B" font-family="OpenSans-Regular, Open Sans" font-size="22" font-weight="normal"><tspan x="210.145" y="186">preflight</tspan></text><text id="if-allowed" fill="#7E7C7B" font-family="OpenSans-Regular, Open Sans" font-size="22" font-weight="normal"><tspan x="198.338" y="441">if allowed</tspan></text><text id="1" fill="#181717" font-family="OpenSans-Regular, Open Sans" font-size="24" font-weight="normal"><tspan x="570.139" y="186">1</tspan></text><text id="2" fill="#181717" font-family="OpenSans-Regular, Open Sans" font-size="24" font-weight="normal"><tspan x="570.139" y="302">2</tspan></text><text id="3" fill="#181717" font-family="OpenSans-Regular, Open Sans" font-size="24" font-weight="normal"><tspan x="570.139" y="443">3</tspan></text><text id="4" fill="#181717" font-family="OpenSans-Regular, Open Sans" font-size="24" font-weight="normal"><tspan x="570.139" y="509">4</tspan></text><text id="Access-Control-Allow" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"> <tspan x="340.89" y="311.33">Access-Control-Allow-Origin</tspan> <tspan x="332" y="329.33">Access-Control-Allow-Methods</tspan> <tspan x="333.473" y="347.33">Access-Control-Allow-Headers</tspan> <tspan x="352.443" y="365.33">Access-Control-Max-Age</tspan></text></g></g></svg> No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" width="620" height="633" viewBox="0 0 620 633"><defs><style>@import url(https://fonts.googleapis.com/css?family=Open+Sans:bold,italic,bolditalic%7CPT+Mono);@font-face{font-family:&apos;PT Mono&apos;;font-weight:700;font-style:normal;src:local(&apos;PT MonoBold&apos;),url(/font/PTMonoBold.woff2) format(&apos;woff2&apos;),url(/font/PTMonoBold.woff) format(&apos;woff&apos;),url(/font/PTMonoBold.ttf) format(&apos;truetype&apos;)}</style></defs><g id="network" fill="none" fill-rule="evenodd" stroke="none" stroke-width="1"><g id="xhr-preflight.svg"><path id="Rectangle-227" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M1 16h128v64H1z"/><text id="JavaScript" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="33" y="50">JavaScript</tspan></text><path id="Rectangle-228" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M240 16h128v64H240z"/><text id="Browser" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="269" y="48">Navegador</tspan></text><path id="Rectangle-229" fill="#FBF2EC" stroke="#DBAF88" stroke-width="2" d="M491 16h128v64H491z"/><text id="Server" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="527.5" y="50">Servidor</tspan></text><path id="Line" stroke="#7E7C7B" stroke-linecap="square" d="M66 82v520M305 82v520M556 82v520"/><path id="Line" fill="#C06334" fill-rule="nonzero" d="M291 133l14 7-14 7-.001-6H67v-2h223.999l.001-6z"/><text id="fetch()" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="166" y="131">fetch()</tspan></text><text id="OPTIONS" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="400" y="173">OPTIONS</tspan></text><text id="Origin-Access-Contro" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="406.721" y="198">Origin</tspan> <tspan x="321.866" y="216">Access-Control-Request-Method</tspan> <tspan x="320" y="234">Access-Control-Request-Headers</tspan></text><path id="Line" fill="#C06334" fill-rule="nonzero" d="M319 285.5v6h237v2H319v6l-14-7 14-7z"/><text id="200-OK" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="407" y="285">200 OK</tspan></text><path id="Line-4" fill="#C06334" fill-rule="nonzero" d="M542 173l14 7-14 7-.001-6H305v-2h236.999l.001-6z"/><path id="Line-2" fill="#C06334" fill-rule="nonzero" d="M319 495v6h237v2H319v6l-14-7 14-7z"/><path id="Line-3" fill="#C06334" fill-rule="nonzero" d="M90.5 544.5v8h214v3h-214v8l-19-9.5 19-9.5z"/><text id="Access-Control-Allow" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="336" y="522">Access-Control-Allow-Origin</tspan></text><text id="Main-HTTP-response" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="355" y="495">Resposta HTTP principal</tspan></text><text id="otherwise-error" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="130" y="570">senão, erro</tspan></text><text id="if-allowed:-success," fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="115.5" y="545">se permitido: sucesso,</tspan></text><path id="Line-5" fill="#C06334" fill-rule="nonzero" d="M542 429l14 7-14 7-.001-6H304v-2h237.999l.001-6z"/><text id="Origin" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="405" y="454">Origin</tspan></text><text id="Main-HTTP-request" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"><tspan x="360" y="429">Requisição HTTP principal</tspan></text><text id="preflight" fill="#7E7C7B" font-family="OpenSans-Regular, Open Sans" font-size="22" font-weight="normal"><tspan x="210.145" y="186">preflight</tspan></text><text id="if-allowed" fill="#7E7C7B" font-family="OpenSans-Regular, Open Sans" font-size="22" font-weight="normal"><tspan x="198.338" y="441">se permitido</tspan></text><text id="1" fill="#181717" font-family="OpenSans-Regular, Open Sans" font-size="24" font-weight="normal"><tspan x="570.139" y="186">1</tspan></text><text id="2" fill="#181717" font-family="OpenSans-Regular, Open Sans" font-size="24" font-weight="normal"><tspan x="570.139" y="302">2</tspan></text><text id="3" fill="#181717" font-family="OpenSans-Regular, Open Sans" font-size="24" font-weight="normal"><tspan x="570.139" y="443">3</tspan></text><text id="4" fill="#181717" font-family="OpenSans-Regular, Open Sans" font-size="24" font-weight="normal"><tspan x="570.139" y="509">4</tspan></text><text id="Access-Control-Allow" fill="#AF6E24" font-family="OpenSans-Regular, Open Sans" font-size="14" font-weight="normal"> <tspan x="340.89" y="311.33">Access-Control-Allow-Origin</tspan> <tspan x="332" y="329.33">Access-Control-Allow-Methods</tspan> <tspan x="333.473" y="347.33">Access-Control-Allow-Headers</tspan> <tspan x="352.443" y="365.33">Access-Control-Max-Age</tspan></text></g></g></svg> No newline at end of file

@gabifs gabifs Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pequeno ajuste (opcional): o rótulo "se permitido" (22px) continua posicionado em x=198.338 com alinhamento à esquerda, como era "if allowed", mas tem dois caracteres a mais. Pela estimativa (cerca de 11 a 12px por caractere), o texto vai até mais ou menos x=325 e cruza a linha vertical do Browser, em x=305 (o rótulo original terminava por volta de x=295). Sugiro deslocá-lo para a esquerda (por exemplo, x em torno de 180) ou usar um rótulo mais curto, conferindo o SVG renderizado. A entrada correspondente em images.yml ("if allowed": position: left) também precisaria ser ajustada.

2. Todas as outras.

Safe Requests are simpler to make, so let's start with them.
Requisições Seguras são mais simples de fazer, então vamos começar por elas.

@gabifs gabifs Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pequeno ajuste (opcional): "Requisições Seguras" está com iniciais maiúsculas no meio da frase, copiando o "Safe Requests" do inglês. Em português, substantivos comuns ficam em minúsculas, e no restante do artigo aparece "requisições seguras".

Suggested change
Requisições Seguras são mais simples de fazer, então vamos começar por elas.
Requisições seguras são mais simples de fazer, então vamos começar por elas.

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

Successfully merging this pull request may close these issues.

2 participants