trgk
June 10, 2025, 9:53am
1
Steps to reproduce:
Go to this URL
https://www.researchgate.net/publication/372533503/figure/fig1/AS:11431281270911835@1723283890520/Carotid-sinus-and-carotid-body-The-carotid-sinus-nerve-a-branch-of-the-glossopharyngeal.jpg
Copy the image
Paste that to Anki.
Notice the 403 error and the resulting image. src
attribute pointing to remote URL, rather than downloading the media.
Gonna make a PR for this. Leaving this post as a reminder.
llama
June 10, 2025, 11:02am
2
1 Like
trgk
June 10, 2025, 11:05am
3
Oh, this had already been discussed.
No, Iām not behind any VPN. It seems like some sites donāt like Ankiās user agent or so.
1 Like
This thread is also related:
Iām on Linux, gnome with x11 and when I add images to notes, I often just click on copy image in Chrome, and paste to anki.
[image]
However, I have been noticing Anki freezing for short or long time (seconds) after I paste each image which shouldnāt happen if itās pasted from the clipboard locally.
Moreover, I occasionally got popups of 4xx errors after the freeze (but the image seems to paste successfully anyways. I didnāt bother to inspect the field html when those happened but I suspect Aā¦
1 Like
trgk
June 10, 2025, 11:26am
5
main
ā phu54321:fix/chrome_image_paste_403
opened 11:19AM - 10 Jun 25 UTC
This PR fixes issues described [here](https://forums.ankiweb.net/t/pasting-some-⦠image-from-chrome-wont-import-the-image-to-the-media-database/62457). Maybe a partial reimplementation of https://github.com/ankitects/anki/commit/abd8759d502bea5707661d17b06787e395794156
## Problem description
When you copy images on browser, with the image, a html snippet is also copied.
```html
<html>
<body>
<img src="https://www.researchgate.net/publication/372533503/figure/fig1/AS:11431281270911835@1723283890520/Carotid-sinus-and-carotid-body-The-carotid-sinus-nerve-a-branch-of-the-glossopharyngeal.jpg"/>
</body>
</html>
```
If user tries to paste this to Anki, since HTML handler kicks in ahead of the image handler. When Anki sees `<img src="https://www.researchgate.net/publication/372533503/figure/fig1/AS:11431281270911835@1723283890520/Carotid-sinus-and-carotid-body-The-carotid-sinus-nerve-a-branch-of-the-glossopharyngeal.jpg"/>`, it tries to download that image, but due to user-agent or other unknown issues it fails with 403 forbidden error. So URL pointing to remote resource persists.


## Bug reproduction step
1. With Chrome browser, go to [this image](https://www.researchgate.net/publication/372533503/figure/fig1/AS:11431281270911835@1723283890520/Carotid-sinus-and-carotid-body-The-carotid-sinus-nerve-a-branch-of-the-glossopharyngeal.jpg) and copy the image.
3. Paste the image to the Anki.
4. Notice `403` forbidden error and image referenced remotely.


## Suggested solution
When Anki detects a single image paste,
- First, try to download the image. If it works, use that. (preserving attributes like `alt`). I tried to make this procedure as backward-compliant as possible.
- If downloading fails, use the image in the clipboard. This drops other attributes like `alt` as I tried to use existing function `EditorWebView._processImage`. Since download failure rarely happens, I hope this won't make much of the trouble.
Posted a quick PR draft. This pr conserves filename and alt when the download succeeds.
1 Like
trgk
June 10, 2025, 11:33am
6
For record, I think anki should download the original image whenever possible instead of using the clipboard data, as it would allowā¦
Animated GIF
Image with transparency (may not be respected on the clipboard)
Lossless embedding of non-jpg images.
trgk
June 14, 2025, 4:47am
7
https://ankiweb.net/shared/info/934503660
Created an addon for the issue. Likely the PR wonāt be merged cause Ankiās undergoing some serious redesign on the card editor.
1 Like
safely
June 15, 2025, 7:15am
8
You might want to insert the image as a reference to keep an image up-to-date. But this shouldnāt be default behavior, so I agree with you. Iām not well into this particular issue, but perhaps the insert-as-reference is already a fallback when image download isnāt working?
After all, itās strange that an error 403 is shown before then displaying the correct image. Maybe a different user agent is used when trying to download the image versus when displaying it for the user? On other images, my Anki just runs into unhandled exceptions.
trgk
June 15, 2025, 9:12am
9
Maybe a different user agent is used when trying to download the image versus when displaying it for the user?
I think so. Anki uses Mozilla/5.0 (compatible; Anki)
as a user agent when retrieving a URL, without any referer or so.