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

Most image links are broken when viewing an app #1989

Open
warpdesign opened this issue Mar 23, 2022 · 11 comments
Open

Most image links are broken when viewing an app #1989

warpdesign opened this issue Mar 23, 2022 · 11 comments

Comments

@warpdesign
Copy link
Contributor

warpdesign commented Mar 23, 2022

image

See https://www.electronjs.org/apps/react-explorer

These images come from the README.md of the repository.

@warpdesign
Copy link
Contributor Author

Looking at the source code, it seems the problem is that each relative images found in readme are modified here:

apps/script/readmes.js

Lines 108 to 111 in 434b074

$relativeImages.each((i, img) => {
$(img).attr(
'src',
`${app.repository}/raw/${defaultBranch}/${$(img).attr('src')}`

Problem is that GitHub now uses CORS to prevent resources from being loaded from another domain, so links like this will be broken.

@warpdesign
Copy link
Contributor Author

warpdesign commented Mar 24, 2022

Actually that's weird: links like this one generated by the readme.js script return a 302 which redirects to https://raw.githubusercontent.com/warpdesign/react-explorer/master/img/react-explorer-theme.png but for some odd reason, the redirect isn't done on electronjs.org. So images appear broken.

I tried to create a simple html file that embbeds the same img file in a personal web server and it works: https://warpdesign.fr/tests/gh/

Not sure why it doesn't work as expected on electronjs.org/apps.

@lexoyo
Copy link
Contributor

lexoyo commented Mar 24, 2022

I believe it is because of the headers:

The resource at “https://github.com/warpdesign/react-explorer/raw/master/img/feature-darktheme.gif” was blocked due to its Cross-Origin-Resource-Policy header (or lack thereof). See https://developer.mozilla.org/docs/Web/HTTP/Cross-Origin_Resource_Policy_(CORP)#

Screenshot from 2022-03-24 09-58-10

@PaulKeefe
Copy link
Contributor

I'm seeing the same thing for all images in Edge.
Failed to load resource: net::ERR_BLOCKED_BY_RESPONSE.NotSameOriginAfterDefaultedToSameOriginByCoep

@yikuansun
Copy link
Contributor

yikuansun commented Apr 1, 2022

YouTube embeds are also broken, seemingly also due to CORS.

@yikuansun
Copy link
Contributor

yikuansun commented Apr 1, 2022

I've got a solution for the image URL's that doesn't involve changing server configuration:

Loop through image elements in the README, fetch their URI's and return the data as Blob, then insert the Blob URI back into the image element.

Edit: this must be done by those who maintain electronjs.org

@warpdesign
Copy link
Contributor Author

I think I found a way to fix CORS errors without touching the server: #2000

@yikuansun
Copy link
Contributor

@warpdesign Cool! Do you know if the YouTube embeds can also be fixed in a similar way?

@warpdesign
Copy link
Contributor Author

@warpdesign Cool! Do you know if the YouTube embeds can also be fixed in a similar way?

I'm not sure. Could you give me a link to an app with such an embed in its description?

@yikuansun
Copy link
Contributor

@warpdesign Here's one: https://www.electronjs.org/apps/wayward

The embedded URL is https://www.youtube.com/embed/kc69XEXiPzE, a perfectly functional embed URL... but cross-origin headers block it.

@warpdesign
Copy link
Contributor Author

@yikuansun I'm afraid there is nothing that can be done for YouTube embeds: the server's CORS rules are too strict and the crossorigin attribute doesn't exist for iframe element.

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

4 participants