Feature request: support loading image synchronously
Reported by
project....@gmail.com,
Feb 18 2018
|
|||||
Issue description
UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36
Steps to reproduce the problem:
Now the image object can only be loaded asynchronously even the data is already in the memory. The example code is shown in the following:
--------------------------------------
var imageDataInBase64 = '.........';
var image = new Image();
image.src = `data:image/png;base64' + imageDataInBase64;
image.onload = function() {
// Loading is done and do something else.
};
--------------------------------------
What is the expected behavior?
What went wrong?
Enforced "loading asynchronously" is painful.
Please review all asynchronous API (such as image, xmlhttprequest and others) in the 2018 because:
1: The core of Chromium is used in many cases other than WEB. NW.js/Electron has millions of users.
2: Provide a set of synchronous APIs with a timeout option! Thus web developers can have more options. "asynchronous only" is not painful.
Did this work before? N/A
Does this work in other browsers? N/A
Chrome version: 64.0.3282.167 Channel: stable
OS Version: OS X 10.13.3
Flash Version:
,
Feb 19 2018
,
Feb 19 2018
As per comment#0 from the reporter considering this issue as Feature request and marking as Untriaged. Thanks!
,
Feb 20 2018
I don't think we can can load synchronously, presuming you mean the JS can assume the image is available on the line after the image.src asignment is made. The Javascript must return so that a document lifecycle can execute to update CSS and fetch the image, even if it is a data URL. I'm tempted to WontFix, but others might differ. Waiting on confirmation from the scheduling team because maybe I am misunderstanding what's possible.
,
Feb 21 2018
Yeah, I don't think this is really compatible with the execution model of JavaScript. If we decoded the image synchronously, we'd be blocking other UI events from getting processed which would lead to a bad user experience. One option might be to allow synchronous image decodes on a worker thread, but I'm really sure what the end goal here is: what data are you depending on from the loaded image? I'll WontFix this for now but please reopen if I missed something.
,
Feb 21 2018
The goal is very simple: keep the code workflow simple and natural. Examples are: var image = new Image(); image.src = `data:image/png;base64' + imageDataInBase64; // If the image is loaded synchronously. Then we can use it now! In Computer Graphics, many cases can depend on images, such as textures/videos etc. myGraphicsTextureObject.addImage(image); //Now we can use the image myGraphicsVideoObject.addImage(image); //Now we can use the image |
|||||
►
Sign in to add a comment |
|||||
Comment 1 by ajha@chromium.org
, Feb 19 2018