Skip to content

Commit

Permalink
Merge branch 'main' into firefox-135
Browse files Browse the repository at this point in the history
  • Loading branch information
whimboo committed Jan 29, 2025
2 parents 03fdfe0 + 6a67167 commit 776a071
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
6 changes: 4 additions & 2 deletions files/en-us/mozilla/firefox/releases/135/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ This article provides information about the changes in Firefox 135 that affect d

#### Media, WebRTC, and Web Audio

- The {{domxref("RTCOutboundRtpStreamStats.mid", "mid")}} and {{domxref("RTCOutboundRtpStreamStats.rid", "rid")}} properties of the {{domxref("RTCOutboundRtpStreamStats")}} interface, and the{{domxref("RTCOutboundRtpStreamStats.mid", "mid")}} property of the {{domxref("RTCInboundRtpStreamStats")}} interface are now supported. ([Firefox bug 1643001](https://bugzil.la/1643001)).

#### Removals

### WebAssembly
Expand All @@ -67,11 +69,11 @@ This article provides information about the changes in Firefox 135 that affect d

- We now support proper queuing of action sequences without race conditions. This is particularly important for WebDriver BiDi's `input.performActions` command, which can be called multiple times in parallel and must execute the enqueued actions sequentially ([Firefox bug 1915798](https://bugzilla.mozilla.org/show_bug.cgi?id=1915798)).

- When dispatching actions, the `input cancel list` is incorrectly updated before the actual action is dispatched. This can cause unexpected side effects if the action fails to execute, potentially leaving a reverse action in place when the actions are released ([Firefox bug 1930845](https://bugzilla.mozilla.org/show_bug.cgi?id=1930845)).
- When dispatching actions, the `input cancel list` is now correctly updated only after the action has been successfully dispatched. Previously, if an action failed to execute, a reverse action could be left in place, leading to unexpected side effects when resetting the state of the `input source` ([Firefox bug 1930845](https://bugzilla.mozilla.org/show_bug.cgi?id=1930845)).

- When performing actions, individual actions are now retried during dispatch, particularly in situations where a single action triggers a navigation that replaces the current browsing context ([Firefox bug 1930530](https://bugzilla.mozilla.org/show_bug.cgi?id=1930530), [Firefox bug 1930090](https://bugzilla.mozilla.org/show_bug.cgi?id=1930090)).

- When performing actions, a `TypeError: can't access property "getActor", browsingContext.currentWindowGlobal is null` error occurred if an action (not the last one) in the action chain closed the window, and the remaining actions were still being dispatched ([Firefox bug 1932916](https://bugzilla.mozilla.org/show_bug.cgi?id=1932916))
- When performing actions, a `TypeError: can't access property "getActor", browsingContext.currentWindowGlobal is null` error occurred if an action (not the last one) in the action chain closed the window, and the remaining actions were still being dispatched ([Firefox bug 1932916](https://bugzilla.mozilla.org/show_bug.cgi?id=1932916)).

- Some Marionette and WebDriver BiDi commands that rely internally on a `requestAnimationFrame` being emitted before returning would hang if the current browsing context was navigated during their execution ([Firefox bug 1937118](https://bugzilla.mozilla.org/show_bug.cgi?id=1937118)).

Expand Down
66 changes: 63 additions & 3 deletions files/en-us/web/api/filereader/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ browser-compat: api.FileReader

The **`FileReader`** interface lets web applications asynchronously read the contents of files (or raw data buffers) stored on the user's computer, using {{domxref("File")}} or {{domxref("Blob")}} objects to specify the file or data to read.

File objects may be obtained from a {{domxref("FileList")}} object returned as a result of a user selecting files using the {{HTMLElement("input")}} element, or from a drag and drop operation's {{domxref("DataTransfer")}} object.

`FileReader` can only access the contents of files that the user has explicitly selected, either using an HTML `<input type="file">` element or by drag and drop. It cannot be used to read a file by pathname from the user's file system. To read files on the client's file system by pathname, use the [File System Access API](/en-US/docs/Web/API/File_System_API). To read server-side files, use {{domxref("Window/fetch", "fetch()")}}, with [CORS](/en-US/docs/Web/HTTP/CORS) permission if reading cross-origin.
File objects may be obtained from a {{domxref("FileList")}} object returned as a result of a user selecting files using the `<input type="file">` element, or from a drag and drop operation's {{domxref("DataTransfer")}} object. `FileReader` can only access the contents of files that the user has explicitly selected; it cannot be used to read a file by pathname from the user's file system. To read files on the client's file system by pathname, use the [File System Access API](/en-US/docs/Web/API/File_System_API). To read server-side files, use {{domxref("Window/fetch", "fetch()")}}, with [CORS](/en-US/docs/Web/HTTP/CORS) permission if reading cross-origin.

{{InheritanceDiagram}}

Expand Down Expand Up @@ -69,6 +67,68 @@ Listen to these events using {{domxref("EventTarget/addEventListener", "addEvent
- {{domxref("FileReader/progress_event", "progress")}}
- : Fired periodically as data is read.

## Examples

### Using FileReader

This example reads and displays the contents of a text file directly in the browser.

#### HTML

```html
<h1>File Reader</h1>
<input type="file" id="file-input" />
<div id="message"></div>
<pre id="file-content"></pre>
```

#### JavaScript

```js
const fileInput = document.getElementById("file-input");
const fileContentDisplay = document.getElementById("file-content");
const messageDisplay = document.getElementById("message");

fileInput.addEventListener("change", handleFileSelection);

function handleFileSelection(event) {
const file = event.target.files[0];
fileContentDisplay.textContent = ""; // Clear previous file content
messageDisplay.textContent = ""; // Clear previous messages

// Validate file existence and type
if (!file) {
showMessage("No file selected. Please choose a file.", "error");
return;
}

if (!file.type.startsWith("text")) {
showMessage("Unsupported file type. Please select a text file.", "error");
return;
}

// Read the file
const reader = new FileReader();
reader.onload = () => {
fileContentDisplay.textContent = reader.result;
};
reader.onerror = () => {
showMessage("Error reading the file. Please try again.", "error");
};
reader.readAsText(file);
}

// Displays a message to the user
function showMessage(message, type) {
messageDisplay.textContent = message;
messageDisplay.style.color = type === "error" ? "red" : "green";
}
```

### Result

{{EmbedLiveSample("Using FileReader", 640, 300)}}

## Specifications

{{Specifications}}
Expand Down

0 comments on commit 776a071

Please sign in to comment.