File API .text() is not supported

Talk about code development, features, specific bugs, enhancements, patches, and similar things.
Forum rules
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific bugs, git, the repositories, etc.

This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.

Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
Post Reply
Lurker_01
Moon lover
Moon lover
Posts: 98
Joined: 2015-06-12, 14:59
Location: Uruguay

File API .text() is not supported

Post by Lurker_01 » 2021-06-06, 23:47

Using https://developer.mozilla.org/en-US/docs/Web/API/FileList
Specific function https://developer.mozilla.org/en-US/docs/Web/API/Blob/text
Working Draft: https://w3c.github.io/FileAPI/#dom-blob-text

Code: Select all

domElem.files[i].text()
Is not supported.
While it is possible to use a file reader as an alternative, in some cases .text() is easier to work with, see function Usage notes.
Firefox 69 implementation bug #1557121, bug #1577311
This makes impossible for a website to read the uploaded data without storage, ej: web game reading imported save file, not using clipboard paste.
To reproduce you could use File List example and use .text() instead of .name under the alert.

Edit: Moved to Browser Development from Web Site compatibility since it is a more relevant board

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 30212
Joined: 2011-08-28, 17:27
Location: Tranås, SE
Contact:

Re: File API .text() is not supported

Post by Moonchild » 2021-06-07, 00:42

Use FileReader.readAsText()
It has the advantage of being widely supported by all browsers and is event-based (meaning you're actually using the native paradigm for JS) as well as being able to use encodings other than UTF-8 if necessary.
"Son, in life you do not fight battles because you expect to win, you fight them merely because they need to be fought." -- Snagglepuss
Image

Lurker_01
Moon lover
Moon lover
Posts: 98
Joined: 2015-06-12, 14:59
Location: Uruguay

Re: File API .text() is not supported

Post by Lurker_01 » 2021-06-07, 01:09

Moonchild wrote:
2021-06-07, 00:42
Use FileReader.readAsText()
Lurker_01 wrote:
2021-06-06, 23:47
While it is possible to use a file reader as an alternative...
Like i said, yes this is a workaround. i was talking with the game developers and said that this API is a Working draft, and that they could use File Reader instead of this shortcut but they treated it as a "browser bug".
This is outside of my control and i am just reporting a problem.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 30212
Joined: 2011-08-28, 17:27
Location: Tranås, SE
Contact:

Re: File API .text() is not supported

Post by Moonchild » 2021-06-07, 01:24

Well we can't do anything about something that isn't a browser bug, no matter if they call it that.
It's already bad enough that we have to implement working draft specs to begin with, let alone ones that have well-supported alternatives that do the exact same thing. The only thing they'd have to do is use the event handler for loaded state instead of a promise (and they can even wrap it in a promise in JS too if they have some aversion to using it as-is, shimming the API).

So the solution is simple: they can either use a broadly-supported API instead of their draft shiny, or lose players.
"Son, in life you do not fight battles because you expect to win, you fight them merely because they need to be fought." -- Snagglepuss
Image

Post Reply