-
Notifications
You must be signed in to change notification settings - Fork 22.7k
Add an example to show how to handle a non-UTF-8 page #39385
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
Conversation
Preview URLs (comment last updated: 2025-05-17 08:39:50) |
This is the first I've heard of You indirectly mentioned that TextEncoder only supports encoding content in UTF-8. Rather than try to encode the modified document back into Also tagging @rebloor and @pepelsbey in case there are MDN editorial considerations that I'm not aware of here. |
|
||
const encoder = new TextEncoder(); | ||
const start1 = encoder.encode( | ||
'<a href="/pc/" class="p-catList_cell p-catList_cell--pc-">' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[mdn-linter] reported by reviewdog 🐶
'<a href="/pc/" class="p-catList_cell p-catList_cell--pc-">' | |
'<a href="/pc/" class="p-catList_cell p-catList_cell--pc-">', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the "," needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionally, no, but the default prettier
settings require trailing commas: https://prettier.io/docs/options#trailing-commas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
browser.webRequest.onBeforeRequest.addListener( | ||
listener, | ||
{ urls: ["https://kakaku.com/"], types: ["main_frame"] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to use https://example.com/?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The page has utf-8 encoding.
This example shows, how to handle a non-UTF-8 page: | ||
|
||
```js | ||
Object.defineProperty(Array.prototype, 'indexOfMulti', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[mdn-linter] reported by reviewdog 🐶
Object.defineProperty(Array.prototype, 'indexOfMulti', { | |
Object.defineProperty(Array.prototype, "indexOfMulti", { |
} | ||
|
||
return i === initial + searchElements.length - 1 ? initial : -1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[mdn-linter] reported by reviewdog 🐶
} | |
}, |
I don't think we should merge this PR. UTF-8 encoding has been an unofficial standard for decades and was formally adopted by WHATWG in Nov, 2018 (whatwg/html#4195). Based on data gathered in this comment on the related WHATWG discussion issue, "out of the 431,851 sites analyzed … merely 0.14%" of websites "include at least one charset that is not Tagging @rebloor for a second opinion. |
Description
The example shows two things:
Motivation
All other examples are for a UTF-8 page.
Additional details
Related issues and pull requests