{ // 获取包含Hugging Face文本的span元素 const spans = link.querySelectorAll('span.whitespace-nowrap, span.hidden.whitespace-nowrap'); spans.forEach(span => { if (span.textContent && span.textContent.trim().match(/Hugging\s*Face/i)) { span.textContent = 'AI快站'; } }); }); // 替换logo图片的alt属性 document.querySelectorAll('img[alt*="Hugging"], img[alt*="Face"]').forEach(img => { if (img.alt.match(/Hugging\s*Face/i)) { img.alt = 'AI快站 logo'; } }); } // 替换导航栏中的链接 function replaceNavigationLinks() { // 已替换标记,防止重复运行 if (window._navLinksReplaced) { return; } // 已经替换过的链接集合,防止重复替换 const replacedLinks = new Set(); // 只在导航栏区域查找和替换链接 const headerArea = document.querySelector('header') || document.querySelector('nav'); if (!headerArea) { return; } // 在导航区域内查找链接 const navLinks = headerArea.querySelectorAll('a'); navLinks.forEach(link => { // 如果已经替换过,跳过 if (replacedLinks.has(link)) return; const linkText = link.textContent.trim(); const linkHref = link.getAttribute('href') || ''; // 替换Spaces链接 - 仅替换一次 if ( (linkHref.includes('/spaces') || linkHref === '/spaces' || linkText === 'Spaces' || linkText.match(/^s*Spacess*$/i)) && linkText !== 'OCR模型免费转Markdown' && linkText !== 'OCR模型免费转Markdown' ) { link.textContent = 'OCR模型免费转Markdown'; link.href = 'https://fast360.xyz'; link.setAttribute('target', '_blank'); link.setAttribute('rel', 'noopener noreferrer'); replacedLinks.add(link); } // 删除Posts链接 else if ( (linkHref.includes('/posts') || linkHref === '/posts' || linkText === 'Posts' || linkText.match(/^s*Postss*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } // 替换Docs链接 - 仅替换一次 else if ( (linkHref.includes('/docs') || linkHref === '/docs' || linkText === 'Docs' || linkText.match(/^s*Docss*$/i)) && linkText !== '模型下载攻略' ) { link.textContent = '模型下载攻略'; link.href = '/'; replacedLinks.add(link); } // 删除Enterprise链接 else if ( (linkHref.includes('/enterprise') || linkHref === '/enterprise' || linkText === 'Enterprise' || linkText.match(/^s*Enterprises*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } }); // 查找可能嵌套的Spaces和Posts文本 const textNodes = []; function findTextNodes(element) { if (element.nodeType === Node.TEXT_NODE) { const text = element.textContent.trim(); if (text === 'Spaces' || text === 'Posts' || text === 'Enterprise') { textNodes.push(element); } } else { for (const child of element.childNodes) { findTextNodes(child); } } } // 只在导航区域内查找文本节点 findTextNodes(headerArea); // 替换找到的文本节点 textNodes.forEach(node => { const text = node.textContent.trim(); if (text === 'Spaces') { node.textContent = node.textContent.replace(/Spaces/g, 'OCR模型免费转Markdown'); } else if (text === 'Posts') { // 删除Posts文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } else if (text === 'Enterprise') { // 删除Enterprise文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } }); // 标记已替换完成 window._navLinksReplaced = true; } // 替换代码区域中的域名 function replaceCodeDomains() { // 特别处理span.hljs-string和span.njs-string元素 document.querySelectorAll('span.hljs-string, span.njs-string, span[class*="hljs-string"], span[class*="njs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换hljs-string类的span中的域名(移除多余的转义符号) document.querySelectorAll('span.hljs-string, span[class*="hljs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换pre和code标签中包含git clone命令的域名 document.querySelectorAll('pre, code').forEach(element => { if (element.textContent && element.textContent.includes('git clone')) { const text = element.innerHTML; if (text.includes('huggingface.co')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 处理特定的命令行示例 document.querySelectorAll('pre, code').forEach(element => { const text = element.innerHTML; if (text.includes('huggingface.co')) { // 针对git clone命令的专门处理 if (text.includes('git clone') || text.includes('GIT_LFS_SKIP_SMUDGE=1')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 特别处理模型下载页面上的代码片段 document.querySelectorAll('.flex.border-t, .svelte_hydrator, .inline-block').forEach(container => { const content = container.innerHTML; if (content && content.includes('huggingface.co')) { container.innerHTML = content.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 特别处理模型仓库克隆对话框中的代码片段 try { // 查找包含"Clone this model repository"标题的对话框 const cloneDialog = document.querySelector('.svelte_hydration_boundary, [data-target="MainHeader"]'); if (cloneDialog) { // 查找对话框中所有的代码片段和命令示例 const codeElements = cloneDialog.querySelectorAll('pre, code, span'); codeElements.forEach(element => { if (element.textContent && element.textContent.includes('huggingface.co')) { if (element.innerHTML.includes('huggingface.co')) { element.innerHTML = element.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { element.textContent = element.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); } // 更精确地定位克隆命令中的域名 document.querySelectorAll('[data-target]').forEach(container => { const codeBlocks = container.querySelectorAll('pre, code, span.hljs-string'); codeBlocks.forEach(block => { if (block.textContent && block.textContent.includes('huggingface.co')) { if (block.innerHTML.includes('huggingface.co')) { block.innerHTML = block.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { block.textContent = block.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); }); } catch (e) { // 错误处理但不打印日志 } } // 当DOM加载完成后执行替换 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); }); } else { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); } // 增加一个MutationObserver来处理可能的动态元素加载 const observer = new MutationObserver(mutations => { // 检查是否导航区域有变化 const hasNavChanges = mutations.some(mutation => { // 检查是否存在header或nav元素变化 return Array.from(mutation.addedNodes).some(node => { if (node.nodeType === Node.ELEMENT_NODE) { // 检查是否是导航元素或其子元素 if (node.tagName === 'HEADER' || node.tagName === 'NAV' || node.querySelector('header, nav')) { return true; } // 检查是否在导航元素内部 let parent = node.parentElement; while (parent) { if (parent.tagName === 'HEADER' || parent.tagName === 'NAV') { return true; } parent = parent.parentElement; } } return false; }); }); // 只在导航区域有变化时执行替换 if (hasNavChanges) { // 重置替换状态,允许再次替换 window._navLinksReplaced = false; replaceHeaderBranding(); replaceNavigationLinks(); } }); // 开始观察document.body的变化,包括子节点 if (document.body) { observer.observe(document.body, { childList: true, subtree: true }); } else { document.addEventListener('DOMContentLoaded', () => { observer.observe(document.body, { childList: true, subtree: true }); }); } })(); \n\n```\n\nIn that document, there are five text nodes, with the following contents:\n\n- `\"\\n \"` (after the `` start tag, a newline followed by four spaces)\n- `\"Aliens?\"` (the contents of the `title` element)\n- `\"\\n \"` (after the `` end tag, a newline followed by two spaces)\n- `\"\\n \"` (after the `` start tag, a newline followed by two spaces)\n- `\"\\n Why yes.\\n \\n\\n\"` (the contents of the `body` element)\n\nEach of those text nodes is an object that has the properties and methods documented in this article.\n\n## Constructor\n\n- {{domxref(\"Text.Text\", \"Text()\")}}\n - : Returns a new `Text` node with the parameter as its textual content.\n\n## Instance properties\n\n_Inherits properties from its parents, {{domxref(\"CharacterData\")}}, {{domxref(\"Node\")}}, and {{domxref(\"EventTarget\")}}._\n\n- {{domxref(\"Text.assignedSlot\")}} {{ReadOnlyInline}}\n - : Returns a {{domxref(\"HTMLSlotElement\")}} representing the {{htmlelement(\"slot\")}} the node is inserted in.\n- {{domxref(\"Text.wholeText\")}} {{ReadOnlyInline}}\n - : Returns a string containing the text of all `Text` nodes logically adjacent to this {{domxref(\"Node\")}}, concatenated in document order.\n\n## Instance methods\n\n_Inherits methods from its parent, {{domxref(\"CharacterData\")}}, {{domxref(\"Node\")}}, and {{domxref(\"EventTarget\")}}._\n\n- {{domxref(\"Text.splitText\")}}\n - : Breaks the node into two nodes at a specified offset.\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- [The DOM API](/en-US/docs/Web/API/Document_Object_Model)\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1524,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/text"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/text/text/index.md"},"content":{"kind":"string","value":"---\ntitle: \"Text: Text() constructor\"\nshort-title: Text()\nslug: Web/API/Text/Text\npage-type: web-api-constructor\nbrowser-compat: api.Text.Text\n---\n\n{{ APIRef(\"DOM\")}}\n\nThe **`Text()`** constructor returns a new {{domxref(\"Text\")}} object\nwith the optional string given in parameter as its textual content.\n\n## Syntax\n\n```js-nolint\nnew Text()\nnew Text(string)\n```\n\n### Parameters\n\n- `string` {{optional_inline}}\n\n### Return value\n\nA new {{domxref(\"Text\")}} object with the content of the `string` parameter, or the empty string if no parameter was given.\n\n## Example\n\n```js\nlet text = new Text(\"Test\");\n```\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- The [DOM API](/en-US/docs/Web/API/Document_Object_Model)\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1525,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/text"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/text/wholetext/index.md"},"content":{"kind":"string","value":"---\ntitle: \"Text: wholeText property\"\nshort-title: wholeText\nslug: Web/API/Text/wholeText\npage-type: web-api-instance-property\nbrowser-compat: api.Text.wholeText\n---\n\n{{ apiref(\"DOM\") }}\n\nThe read-only **`wholeText`** property of the {{domxref(\"Text\")}} interface\nreturns the full text of all {{domxref(\"Text\")}} nodes logically adjacent to the node.\nThe text is concatenated in document order.\nThis allows specifying any text node and obtaining all adjacent text as a single string.\n\n> **Note:** This is similar to call {{domxref(\"Node.normalize()\")}} followed by reading the text value,\n> but without modifying the tree.\n\n## Value\n\nA string with the concatenated text.\n\n## Example\n\nSuppose you have the following simple paragraph within your webpage:\n\n```html\n

\n Through-hiking is great!\n No insipid election coverage! However,\n casting a ballot\n is tricky.\n

\n```\n\nYou decide you don't like the middle sentence, so you remove it:\n\n```js\nconst paragraph = document.querySelector(\"p\"); // Reads the paragraph\nparagraph.removeChild(para.childNodes[1]); // Delete the strong element\n```\n\nNow you end up with _\"Through-hiking is great! However, casting a ballot is tricky.\"_, with two nodes before the hyperlink:\n\n1. A {{domxref(\"Text\")}} containing the string `\"Through-hiking is great!\"`\n2. A second `Text` node containing the string `\" However, \"`\n\nTo get those two nodes at once, you would call `para.childNodes[0].wholeText`:\n\n```js\nconsole.log(`'${paragraph.childNodes[0].wholeText}'`); // 'Through-hiking is great! However, '\n```\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- The {{domxref(\"Text\")}} interface it belongs to.\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1526,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/text"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/text/splittext/index.md"},"content":{"kind":"string","value":"---\ntitle: \"Text: splitText() method\"\nshort-title: splitText()\nslug: Web/API/Text/splitText\npage-type: web-api-instance-method\nbrowser-compat: api.Text.splitText\n---\n\n{{APIRef(\"DOM\")}}\n\nThe **`splitText()`** method of the {{domxref(\"Text\")}} interface\nbreaks the {{domxref(\"Text\")}} node into two nodes at the specified offset,\nkeeping both nodes in the tree as siblings.\n\nAfter the split, the current node contains all the content\nup to the specified offset point,\nand a newly created node of the same type contains the remaining text.\nThe newly created node is returned to the caller.\nIf the original node had a parent, the new node is inserted as the next sibling of the original node.\nIf the offset is equal to the length of the original node,\nthe newly created node has no data.\n\nSeparated text nodes can be concatenated using the {{domxref(\"Node.normalize()\")}}\nmethod.\n\n## Syntax\n\n```js-nolint\nnewNode = textNode.splitText(offset)\n```\n\n### Parameters\n\n- `offset`\n - : The index immediately before which to break the text node.\n\n### Return value\n\nReturns the newly created {{domxref(\"Text\")}} node that contains the text after the\nspecified offset point.\n\n### Exceptions\n\n- `IndexSizeError` {{domxref(\"DOMException\")}}\n - : Thrown if the specified offset is negative or is greater\n than the number of 16-bit units in the node's text.\n- `NoModificationAllowedError` {{domxref(\"DOMException\")}}\n - : Thrown if the node is read-only.\n\n## Example\n\nIn this example, the text of a {{HTMLElement(\"p\")}} is split into two text nodes, and a\n{{HTMLElement(\"u\")}} is inserted between them.\n\n```html\n

foobar

\n```\n\n```js\nconst p = document.querySelector(\"p\");\n\n// Get contents of

as a text node\nconst foobar = p.firstChild;\n\n// Split 'foobar' into two text nodes, 'foo' and 'bar',\n// and save 'bar' as a const\nconst bar = foobar.splitText(3);\n\n// Create a element containing ' new content '\nconst u = document.createElement(\"u\");\nu.appendChild(document.createTextNode(\" new content \"));\n\n// Add before 'bar'\np.insertBefore(u, bar);\n\n// The result is:

foo new content bar

\n```\n\n{{EmbedLiveSample(\"Example\", 700, 70)}}\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- The {{domxref(\"Text\")}} interface it belongs to.\n- The opposite method: {{domxref(\"Node.normalize\")}}.\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1527,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/text"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/text/assignedslot/index.md"},"content":{"kind":"string","value":"---\ntitle: \"Text: assignedSlot property\"\nshort-title: assignedSlot\nslug: Web/API/Text/assignedSlot\npage-type: web-api-instance-property\nbrowser-compat: api.Text.assignedSlot\n---\n\n{{APIRef(\"DOM\")}}\n\nThe read-only **`assignedSlot`** property of the {{domxref(\"Text\")}} interface\nreturns the {{domxref(\"HTMLSlotElement\")}} object associated with the element.\n\n## Value\n\nAn {{domxref(\"HTMLSlotElement\")}},\nor `null` if no {{HTMLElement(\"slot\")}} element is associated with the text node.\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1528,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/bluetooth/index.md"},"content":{"kind":"string","value":"---\ntitle: Bluetooth\nslug: Web/API/Bluetooth\npage-type: web-api-interface\nstatus:\n - experimental\nbrowser-compat: api.Bluetooth\n---\n\n{{APIRef(\"Bluetooth API\")}}{{securecontext_header}}{{SeeCompatTable}}\n\nThe **`Bluetooth`** interface of the [Web Bluetooth API](/en-US/docs/Web/API/Web_Bluetooth_API) returns a\n{{jsxref(\"Promise\")}} to a {{domxref(\"BluetoothDevice\")}} object with the specified\noptions.\n\n{{InheritanceDiagram}}\n\n## Instance properties\n\n_Inherits properties from its parent {{domxref(\"EventTarget\")}}._\n\n## Instance methods\n\n- {{domxref(\"Bluetooth.getAvailability\",\"Bluetooth.getAvailability()\")}} {{Experimental_Inline}}\n - : Returns a {{jsxref(\"Promise\")}} that resolved to a boolean value indicating\n whether the user-agent has the ability to support Bluetooth. Some user-agents let the\n user configure an option that affects what is returned by this value. If this option\n is set, that is the value returned by this method.\n- {{domxref(\"Bluetooth.getDevices\",\"Bluetooth.getDevices()\")}} {{Experimental_Inline}}\n - : Returns a {{jsxref(\"Promise\")}} that resolved to an array of\n {{domxref(\"BluetoothDevice\")}}s which the origin already obtained permission for via a\n call to {{domxref(\"Bluetooth.requestDevice\",\"Bluetooth.requestDevice()\")}}.\n- {{domxref(\"Bluetooth.requestDevice\",\"Bluetooth.requestDevice()\")}} {{Experimental_Inline}}\n - : Returns a {{jsxref(\"Promise\")}} to a {{domxref(\"BluetoothDevice\")}} object with the\n specified options.\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1529,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/bluetooth"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/bluetooth/requestdevice/index.md"},"content":{"kind":"string","value":"---\ntitle: \"Bluetooth: requestDevice() method\"\nshort-title: requestDevice()\nslug: Web/API/Bluetooth/requestDevice\npage-type: web-api-instance-method\nstatus:\n - experimental\nbrowser-compat: api.Bluetooth.requestDevice\n---\n\n{{APIRef(\"Bluetooth API\")}} {{securecontext_header}}{{SeeCompatTable}}\n\nThe **`Bluetooth.requestDevice()`** method of the\n{{domxref(\"Bluetooth\")}} interface returns a {{jsxref(\"Promise\")}} to a\n{{domxref(\"BluetoothDevice\")}} object with the specified options. If there is no chooser\nUI, this method returns the first device matching the criteria.\n\n## Syntax\n\n```js-nolint\nrequestDevice()\nrequestDevice(options)\n```\n\n### Parameters\n\n- `options` {{optional_inline}}\n - : An object that sets options for the device request. The available options are:\n - `filters[]`\n - : An array of `BluetoothScanFilters`. This\n filter consists of an array of `BluetoothServiceUUID`s, a\n `name` parameter, and a `namePrefix` parameter.\n - `optionalServices[]`\n - : An array of `BluetoothServiceUUID`s.\n - `acceptAllDevices`\n - : A boolean value indicating that the\n requesting script can accept all Bluetooth devices. The default is\n `false`.\n\n### Return value\n\nA {{jsxref(\"Promise\")}} to a {{domxref(\"BluetoothDevice\")}} object.\n\n### Exceptions\n\n- {{jsxref(\"TypeError\")}}\n - : Thrown if the provided `options` do not make sense. For example,\n `options.filters` is present and `options.acceptAllDevices` is\n `true`, or if `options.filters` is not present and\n `options.acceptAllDevices` is `false`. Or\n `options.filters` is `[]`.\n- `NotFoundError` {{domxref(\"DOMException\")}}\n - : Thrown if there is no Bluetooth device that matches the specified options.\n- `SecurityError` {{domxref(\"DOMException\")}}\n - : Thrown if this operation is not permitted in this context due to security concerns. For\n example, it is called from insecure origin.\n\n## Examples\n\n```js\n// Discovery options match any devices advertising:\n// . The standard heart rate service.\n// . Both 16-bit service IDs 0x1802 and 0x1803.\n// . A proprietary 128-bit UUID service c48e6067-5295-48d3-8d5c-0395f61792b1.\n// . Devices with name \"ExampleName\".\n// . Devices with name starting with \"Prefix\".\n//\n// And enables access to the battery service if devices\n// include it, even if devices do not advertise that service.\nlet options = {\n filters: [\n { services: [\"heart_rate\"] },\n { services: [0x1802, 0x1803] },\n { services: [\"c48e6067-5295-48d3-8d5c-0395f61792b1\"] },\n { name: \"ExampleName\" },\n { namePrefix: \"Prefix\" },\n ],\n optionalServices: [\"battery_service\"],\n};\n\nnavigator.bluetooth\n .requestDevice(options)\n .then((device) => {\n console.log(`Name: ${device.name}`);\n // Do something with the device.\n })\n .catch((error) => console.error(`Something went wrong. ${error}`));\n```\n\n[Detailed examples](https://webbluetoothcg.github.io/web-bluetooth/#example-filter-by-services) are in the specification.\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1530,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/bluetooth"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/bluetooth/getavailability/index.md"},"content":{"kind":"string","value":"---\ntitle: \"Bluetooth: getAvailability() method\"\nshort-title: getAvailability()\nslug: Web/API/Bluetooth/getAvailability\npage-type: web-api-instance-method\nstatus:\n - experimental\nbrowser-compat: api.Bluetooth.getAvailability\n---\n\n{{securecontext_header}}{{SeeCompatTable}}{{APIRef(\"Bluetooth API\")}}\n\nThe **`getAvailability()`** method of the {{DOMxRef(\"Bluetooth\")}} interface returns `true` if the device has a Bluetooth adapter, and false otherwise (unless the user has configured the browser to not expose a real value).\n\n> **Note:** A user might not allow use of Web Bluetooth API, even if\n> `getAvailability()` returns `true`\n> ({{DOMxRef(\"Bluetooth.requestDevice\",\"navigator.bluetooth.requestDevice()\")}} might\n> not resolve with a {{DOMxRef(\"BluetoothDevice\")}}). Also, a user can configure their browser to return a fixed value instead of a real one.\n\n## Syntax\n\n```js-nolint\ngetAvailability()\n```\n\n### Parameters\n\nNone.\n\n### Return value\n\nA {{JSxRef(\"Promise\")}} that resolves with {{JSxRef(\"Boolean\")}}.\n\n## Exceptions\n\nThis method doesn't throw any exceptions.\n\n## Examples\n\nThe following snippet prints out a message in the console specifying whether or not\nBluetooth is supported:\n\n```js\nnavigator.bluetooth.getAvailability().then((available) => {\n if (available) {\n console.log(\"This device supports Bluetooth!\");\n } else {\n console.log(\"Doh! Bluetooth is not supported\");\n }\n});\n```\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1531,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/bluetooth"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/bluetooth/getdevices/index.md"},"content":{"kind":"string","value":"---\ntitle: \"Bluetooth: getDevices() method\"\nshort-title: getDevices()\nslug: Web/API/Bluetooth/getDevices\npage-type: web-api-instance-method\nstatus:\n - experimental\nbrowser-compat: api.Bluetooth.getDevices\n---\n\n{{securecontext_header}}{{SeeCompatTable}}{{APIRef(\"Bluetooth API\")}}\n\nThe **`getDevices()`** method of\n{{DOMxRef(\"Bluetooth\")}} interface of [Web Bluetooth API](/en-US/docs/Web/API/Web_Bluetooth_API) exposes the\nBluetooth devices this origin is allowed to access. This method does not display any\npermission prompts.\n\n> **Note:** This method returns a {{DOMxRef(\"BluetoothDevice\")}} for each\n> device the origin is currently allowed to access, even the ones that are out of range\n> or powered off.\n\n## Syntax\n\n```js-nolint\ngetDevices()\n```\n\n### Parameters\n\nNone.\n\n### Return value\n\nA {{JSxRef(\"Promise\")}} that resolves with an array of {{DOMxRef(\"BluetoothDevice\")}}s.\n\n## Exceptions\n\nThis method doesn't throw any exceptions.\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1532,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/filesystemwritablefilestream/index.md"},"content":{"kind":"string","value":"---\ntitle: FileSystemWritableFileStream\nslug: Web/API/FileSystemWritableFileStream\npage-type: web-api-interface\nbrowser-compat: api.FileSystemWritableFileStream\n---\n\n{{securecontext_header}}{{APIRef(\"File System API\")}}\n\nThe **`FileSystemWritableFileStream`** interface of the {{domxref(\"File System API\", \"File System API\", \"\", \"nocode\")}} is a {{domxref('WritableStream')}} object with additional convenience methods, which operates on a single file on disk. The interface is accessed through the {{domxref('FileSystemFileHandle.createWritable()')}} method.\n\n{{InheritanceDiagram}}\n\n## Instance properties\n\n_Inherits properties from its parent, {{DOMxRef(\"WritableStream\")}}._\n\n## Instance methods\n\n_Inherits methods from its parent, {{DOMxRef(\"WritableStream\")}}._\n\n- {{domxref('FileSystemWritableFileStream.write()')}}\n - : Writes content into the file the method is called on, at the current file cursor offset.\n- {{domxref('FileSystemWritableFileStream.seek()')}}\n - : Updates the current file cursor offset to the position (in bytes) specified.\n- {{domxref('FileSystemWritableFileStream.truncate()')}}\n - : Resizes the file associated with the stream to be the specified size in bytes.\n\n## Examples\n\nThe following asynchronous function opens the 'Save File' picker, which returns a {{domxref('FileSystemFileHandle')}} once a file is selected. From this, a writable stream is created using the {{domxref('FileSystemFileHandle.createWritable()')}} method.\n\nA text string is then written to the stream, which is subsequently closed.\n\n```js\nasync function saveFile() {\n // create a new handle\n const newHandle = await window.showSaveFilePicker();\n\n // create a FileSystemWritableFileStream to write to\n const writableStream = await newHandle.createWritable();\n\n // write our file\n await writableStream.write(\"This is my file content\");\n\n // close the file and write the contents to disk.\n await writableStream.close();\n}\n```\n\nThe following examples show different options that can be passed into the `write()` method.\n\n```js\n// just pass in the data (no options)\nwritableStream.write(data);\n\n// writes the data to the stream from the determined position\nwritableStream.write({ type: \"write\", position, data });\n\n// updates the current file cursor offset to the position specified\nwritableStream.write({ type: \"seek\", position });\n\n// resizes the file to be size bytes long\nwritableStream.write({ type: \"truncate\", size });\n```\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- [File System API](/en-US/docs/Web/API/File_System_API)\n- [The File System Access API: simplifying access to local files](https://developer.chrome.com/docs/capabilities/web-apis/file-system-access)\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1533,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/filesystemwritablefilestream"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/filesystemwritablefilestream/truncate/index.md"},"content":{"kind":"string","value":"---\ntitle: \"FileSystemWritableFileStream: truncate() method\"\nshort-title: truncate()\nslug: Web/API/FileSystemWritableFileStream/truncate\npage-type: web-api-instance-method\nbrowser-compat: api.FileSystemWritableFileStream.truncate\n---\n\n{{securecontext_header}}{{APIRef(\"File System API\")}}\n\nThe **`truncate()`** method of the {{domxref(\"FileSystemWritableFileStream\")}} interface resizes the file associated with the stream to the specified size in bytes.\n\nIf the size specified is larger than the current file size the file is padded with `0x00` bytes.\n\nThe file cursor is also updated when `truncate()` is called.\nIf the offset is smaller than the size, it remains unchanged.\nIf the offset is larger than size, the offset is set to that size.\nThis ensures that subsequent writes do not error.\n\nNo changes are written to the actual file on disk until the stream has been closed.\nChanges are typically written to a temporary file instead.\n\n## Syntax\n\n```js-nolint\ntruncate(size)\n```\n\n### Parameters\n\n- `size`\n - : A number specifying the number of bytes to resize the stream to.\n\n### Return value\n\nA {{jsxref('Promise')}} that returns `undefined`.\n\n### Exceptions\n\n- `NotAllowedError` {{domxref(\"DOMException\")}}\n - : Thrown if {{domxref('PermissionStatus.state')}} is not `granted`.\n- `QuotaExceededError` {{domxref(\"DOMException\")}}\n - : Thrown if the new size of the file is larger than the original size of the file, and exceeds the browser's [storage quota](/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria).\n- {{jsxref(\"TypeError\")}}\n - : Thrown if `size` is not a number or not defined.\n\n## Examples\n\nThe following asynchronous function opens the 'Save File' picker, which returns a {{domxref('FileSystemFileHandle')}} once a file is selected. From this, a writable stream is created using the {{domxref('FileSystemFileHandle.createWritable()')}} method.\n\nNext, we write to the stream:\n\n1. A text string is written to the stream.\n2. The `truncate()` method is used to resize the file to 8 bytes.\n3. A second text string is written to the start of the stream, overwriting the first write.\n\nThe stream is then closed.\n\n```js\nasync function saveFile() {\n try {\n // create a new handle\n const newHandle = await window.showSaveFilePicker();\n\n // create a FileSystemWritableFileStream to write to\n const writableStream = await newHandle.createWritable();\n\n // write our file\n await writableStream.write(\"This is my first file content\");\n await writableStream.truncate(8);\n await writableStream.write(\"my second file content\");\n\n // close the file and write the contents to disk.\n await writableStream.close();\n } catch (err) {\n console.error(err.name, err.message);\n }\n}\n```\n\nIf you run the above function and then open the resulting file created on disk, you should see the text \"This is my second file content\".\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- [File System API](/en-US/docs/Web/API/File_System_API)\n- [The File System Access API: simplifying access to local files](https://developer.chrome.com/docs/capabilities/web-apis/file-system-access)\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1534,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/filesystemwritablefilestream"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/filesystemwritablefilestream/seek/index.md"},"content":{"kind":"string","value":"---\ntitle: \"FileSystemWritableFileStream: seek() method\"\nshort-title: seek()\nslug: Web/API/FileSystemWritableFileStream/seek\npage-type: web-api-instance-method\nbrowser-compat: api.FileSystemWritableFileStream.seek\n---\n\n{{securecontext_header}}{{APIRef(\"File System API\")}}\n\nThe **`seek()`** method of the {{domxref(\"FileSystemWritableFileStream\")}} interface updates the current file cursor offset to the position (in bytes) specified when calling the method.\n\n## Syntax\n\n```js-nolint\nseek(position)\n```\n\n### Parameters\n\n- `position`\n - : A number specifying the byte position from the beginning of the file.\n\n### Return value\n\nA {{jsxref('Promise')}} that returns `undefined`.\n\n### Exceptions\n\n- `NotAllowedError` {{domxref(\"DOMException\")}}\n - : Thrown if {{domxref('PermissionStatus.state')}} is not `granted`.\n- {{jsxref(\"TypeError\")}}\n - : Thrown if `position` is not a number or not defined.\n\n## Examples\n\nThe following asynchronous function opens the 'Save File' picker, which returns a {{domxref('FileSystemFileHandle')}} once a file is selected. From this, a writable stream is created using the {{domxref('FileSystemFileHandle.createWritable()')}} method.\n\nNext, we write to the stream:\n\n1. A text string is written to the stream.\n2. The `seek()` method is used to put the cursor at the start of the stream.\n3. A second text string is written to the start of the stream, overwriting the first write.\n\nThe stream is then closed.\n\n```js\nasync function saveFile() {\n try {\n // create a new handle\n const newHandle = await window.showSaveFilePicker();\n\n // create a FileSystemWritableFileStream to write to\n const writableStream = await newHandle.createWritable();\n\n // write our file\n await writableStream.write(\"My first file content\");\n await writableStream.seek(0);\n await writableStream.write(\"My second file content\");\n\n // close the file and write the contents to disk.\n await writableStream.close();\n } catch (err) {\n console.error(err.name, err.message);\n }\n}\n```\n\nIf you run the above function and then open the resulting file created on disk, you should see the text \"My second file content\".\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- [File System API](/en-US/docs/Web/API/File_System_API)\n- [The File System Access API: simplifying access to local files](https://developer.chrome.com/docs/capabilities/web-apis/file-system-access)\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1535,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/filesystemwritablefilestream"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/filesystemwritablefilestream/write/index.md"},"content":{"kind":"string","value":"---\ntitle: \"FileSystemWritableFileStream: write() method\"\nshort-title: write()\nslug: Web/API/FileSystemWritableFileStream/write\npage-type: web-api-instance-method\nbrowser-compat: api.FileSystemWritableFileStream.write\n---\n\n{{securecontext_header}}{{APIRef(\"File System API\")}}\n\nThe **`write()`** method of the {{domxref(\"FileSystemWritableFileStream\")}} interface writes content into the file the method is called on, at the current file cursor offset.\n\nNo changes are written to the actual file on disk until the stream has been closed.\nChanges are typically written to a temporary file instead. This method can also be used to seek to a byte point within the stream and truncate to modify the total bytes the file contains.\n\n## Syntax\n\n```js-nolint\nwrite(data)\n```\n\n### Parameters\n\n- `data`\n\n - : Can be one of the following:\n\n - The file data to write, in the form of an {{jsxref(\"ArrayBuffer\")}}, {{jsxref(\"TypedArray\")}}, {{jsxref(\"DataView\")}}, {{domxref('Blob')}}, or string.\n - An object containing the following properties:\n\n - `type`\n - : A string that is one of `\"write\"`, `\"seek\"`, or `\"truncate\"`.\n - `data`\n - : The file data to write. Can be an {{jsxref(\"ArrayBuffer\")}}, {{jsxref(\"TypedArray\")}}, {{jsxref(\"DataView\")}}, {{domxref('Blob')}}, or string. This property is required if `type` is set to `\"write\"`.\n - `position`\n - : The byte position the current file cursor should move to if type `\"seek\"` is used. Can also be set if `type` is `\"write\"`, in which case the write will start at the specified position.\n - `size`\n - : A number representing the number of bytes the stream should contain. This property is required if `type` is set to `\"truncate\"`.\n\n### Return value\n\nA {{jsxref('Promise')}} that returns `undefined`.\n\n### Exceptions\n\n- `NotAllowedError` {{domxref(\"DOMException\")}}\n - : Thrown if {{domxref('PermissionStatus.state')}} is not `granted`.\n- `QuotaExceededError` {{domxref(\"DOMException\")}}\n - : Thrown if the new size of the file is larger than the original size of the file, and exceeds the browser's [storage quota](/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria).\n- {{jsxref(\"TypeError\")}}\n - : Thrown if `data` is undefined, or if `position` or `size` aren't valid.\n\n## Examples\n\nThe following asynchronous function opens the 'Save File' picker, which returns a {{domxref('FileSystemFileHandle')}} once a file is selected. From this, a writable stream is created using the {{domxref('FileSystemFileHandle.createWritable()')}} method.\n\nA text string is then written to the stream, which is subsequently closed.\n\n```js\nasync function saveFile() {\n try {\n // create a new handle\n const newHandle = await window.showSaveFilePicker();\n\n // create a FileSystemWritableFileStream to write to\n const writableStream = await newHandle.createWritable();\n\n // write our file\n await writableStream.write(\"This is my file content\");\n\n // close the file and write the contents to disk.\n await writableStream.close();\n } catch (err) {\n console.error(err.name, err.message);\n }\n}\n```\n\nThe following examples show different options that can be passed into the `write()` method.\n\n```js\n// just pass in the data (no options)\nwritableStream.write(data);\n\n// writes the data to the stream from the determined position\nwritableStream.write({ type: \"write\", position, data });\n\n// updates the current file cursor offset to the position specified\nwritableStream.write({ type: \"seek\", position });\n\n// resizes the file to be size bytes long\nwritableStream.write({ type: \"truncate\", size });\n```\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- [File System API](/en-US/docs/Web/API/File_System_API)\n- [The File System Access API: simplifying access to local files](https://developer.chrome.com/docs/capabilities/web-apis/file-system-access)\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1536,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/htmlheadingelement/index.md"},"content":{"kind":"string","value":"---\ntitle: HTMLHeadingElement\nslug: Web/API/HTMLHeadingElement\npage-type: web-api-interface\nbrowser-compat: api.HTMLHeadingElement\n---\n\n{{ APIRef(\"HTML DOM\") }}\n\nThe **`HTMLHeadingElement`** interface represents the different heading elements, [`

` through `

`](/en-US/docs/Web/HTML/Element/Heading_Elements). It inherits methods and properties from the {{domxref(\"HTMLElement\")}} interface.\n\n{{InheritanceDiagram}}\n\n## Instance properties\n\n_Inherits properties from its parent, {{domxref(\"HTMLElement\")}}._\n\n- {{domxref(\"HTMLHeadingElement.align\")}} {{deprecated_inline}}\n - : A string representing an enumerated attribute indicating alignment of the heading with respect to the surrounding context. The possible values are `\"left\"`, `\"right\"`, `\"justify\"`, and `\"center\"`.\n\n## Instance methods\n\n_No specific method; inherits methods from its parent, {{domxref(\"HTMLElement\")}}._\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- The HTML element implementing this interface: {{ HTMLElement(\"Heading_Elements\", \"h1\")}}, {{ HTMLElement(\"Heading_Elements\", \"h2\")}}, {{ HTMLElement(\"Heading_Elements\", \"h3\")}}, {{ HTMLElement(\"Heading_Elements\", \"h4\")}}, {{ HTMLElement(\"Heading_Elements\", \"h5\")}}, and {{ HTMLElement(\"Heading_Elements\", \"h6\")}}.\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1537,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/audioparammap/index.md"},"content":{"kind":"string","value":"---\ntitle: AudioParamMap\nslug: Web/API/AudioParamMap\npage-type: web-api-interface\nbrowser-compat: api.AudioParamMap\n---\n\n{{APIRef(\"Web Audio API\")}}\n\nThe **`AudioParamMap`** interface of the [Web Audio API](/en-US/docs/Web/API/Web_Audio_API) represents an iterable and read-only set of multiple audio parameters.\n\nAn `AudioParamMap` instance is a read-only [`Map`-like object](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#map-like_browser_apis), in which each key is the name string for a parameter, and the corresponding value is an {{domxref(\"AudioParam\")}} containing the value of that parameter.\n\n## Instance properties\n\n- {{domxref(\"AudioParamMap.size\", \"size\")}}\n - : ?\n\n## Instance methods\n\n- {{domxref(\"AudioParamMap.entries\", \"entries()\")}}\n - : ?\n- {{domxref(\"AudioParamMap.forEach\", \"forEach()\")}}\n - : ?\n- {{domxref(\"AudioParamMap.has\", \"has()\")}}\n - : ?\n- {{domxref(\"AudioParamMap.keys\", \"keys()\")}}\n - : ?\n- {{domxref(\"AudioParamMap.values\", \"values()\")}}\n - : ?\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1538,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/animationplaybackevent/index.md"},"content":{"kind":"string","value":"---\ntitle: AnimationPlaybackEvent\nslug: Web/API/AnimationPlaybackEvent\npage-type: web-api-interface\nbrowser-compat: api.AnimationPlaybackEvent\n---\n\n{{ APIRef(\"Web Animations\") }}\n\nThe AnimationPlaybackEvent interface of the [Web Animations API](/en-US/docs/Web/API/Web_Animations_API) represents animation events.\n\nAs animations play, they report changes to their {{domxref(\"Animation.playState\", \"playState\")}} through animation events.\n\n{{InheritanceDiagram}}\n\n## Constructor\n\n- {{domxref(\"AnimationPlaybackEvent.AnimationPlaybackEvent\", \"AnimationPlaybackEvent()\")}}\n - : Constructs a new `AnimationPlaybackEvent` object instance.\n\n## Instance properties\n\n- {{domxref(\"AnimationPlaybackEvent.currentTime\")}} {{ReadOnlyInline}}\n - : The current time of the animation that generated the event.\n- {{domxref(\"AnimationPlaybackEvent.timelineTime\")}} {{ReadOnlyInline}}\n - : The time value of the timeline of the animation that generated the event.\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- [Web Animations API](/en-US/docs/Web/API/Web_Animations_API)\n- {{domxref(\"Animation.playState\")}}\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1539,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/animationplaybackevent"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/animationplaybackevent/currenttime/index.md"},"content":{"kind":"string","value":"---\ntitle: \"AnimationPlaybackEvent: currentTime property\"\nshort-title: currentTime\nslug: Web/API/AnimationPlaybackEvent/currentTime\npage-type: web-api-instance-property\nbrowser-compat: api.AnimationPlaybackEvent.currentTime\n---\n\n{{ APIRef(\"Web Animations\") }}\n\nThe **`currentTime`** read-only property of the {{domxref(\"AnimationPlaybackEvent\")}} interface represents the current time of the animation that generated the event at the moment the event is queued. This will be unresolved if the animation was `idle` at the time the event was generated.\n\n## Value\n\nA number representing the current time in milliseconds, or `null`.\n\n## Reduced time precision\n\nTo offer protection against timing attacks and [fingerprinting](/en-US/docs/Glossary/Fingerprinting), the precision of `playbackEvent.currentTime` might get rounded depending on browser settings.\nIn Firefox, the `privacy.reduceTimerPrecision` preference is enabled by default and defaults to 20 µs in Firefox 59; in 60, it will be 2 ms.\n\n```js\n// reduced time precision (2ms) in Firefox 60\nplaybackEvent.currentTime;\n// 23.404\n// 24.192\n// 25.514\n// …\n\n// reduced time precision with `privacy.resistFingerprinting` enabled\nplaybackEvent.currentTime;\n// 49.8\n// 50.6\n// 51.7\n// …\n```\n\nIn Firefox, you can also enabled `privacy.resistFingerprinting`, the precision will be 100ms or the value of `privacy.resistFingerprinting.reduceTimerPrecision.microseconds`, whichever is larger.\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- [Web Animations API](/en-US/docs/Web/API/Web_Animations_API)\n- {{domxref(\"AnimationPlayBackEvent\")}}\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1540,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/animationplaybackevent"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/animationplaybackevent/timelinetime/index.md"},"content":{"kind":"string","value":"---\ntitle: \"AnimationPlaybackEvent: timelineTime property\"\nshort-title: timelineTime\nslug: Web/API/AnimationPlaybackEvent/timelineTime\npage-type: web-api-instance-property\nbrowser-compat: api.AnimationPlaybackEvent.timelineTime\n---\n\n{{ APIRef(\"Web Animations\") }}\n\nThe **`timelineTime`** read-only property of the {{domxref(\"AnimationPlaybackEvent\")}} interface represents the time value of the animation's {{domxref(\"AnimationTimeline\", \"timeline\")}} at the moment the event is queued. This will be unresolved if the animation was not associated with a timeline at the time the event was generated or if the associated timeline was inactive.\n\n## Value\n\nA number representing the current time in milliseconds, or `null`.\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- [Web Animations API](/en-US/docs/Web/API/Web_Animations_API)\n- {{domxref(\"AnimationPlayBackEvent\")}}\n- {{domxref(\"AnimationTimeline\")}}\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1541,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/animationplaybackevent"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/animationplaybackevent/animationplaybackevent/index.md"},"content":{"kind":"string","value":"---\ntitle: \"AnimationPlaybackEvent: AnimationPlaybackEvent() constructor\"\nshort-title: AnimationPlaybackEvent()\nslug: Web/API/AnimationPlaybackEvent/AnimationPlaybackEvent\npage-type: web-api-constructor\nbrowser-compat: api.AnimationPlaybackEvent.AnimationPlaybackEvent\n---\n\n{{ APIRef(\"Web Animations\") }}\n\nThe **`AnimationPlaybackEvent()`** constructor of the [Web Animations API](/en-US/docs/Web/API/Web_Animations_API) returns a new {{domxref(\"AnimationPlaybackEvent\")}} object instance.\n\n## Syntax\n\n```js-nolint\nnew AnimationPlaybackEvent(type)\nnew AnimationPlaybackEvent(type, options)\n```\n\n### Parameters\n\n- `type`\n - : A string with the name of the event.\n It is case-sensitive and browsers set it to `cancel`, `finish`, or `remove`.\n- `options` {{optional_inline}}\n - : An object that, _in addition of the properties defined in {{domxref(\"Event/Event\", \"Event()\")}}_, has the following properties:\n - `detail` {{optional_inline}}\n - : An event-dependent value associated with the event. Defaults to `null`.\n\n### Return value\n\nA new {{domxref(\"AnimationPlaybackEvent\")}} object.\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- [Web Animations API](/en-US/docs/Web/API/Web_Animations_API)\n- {{domxref(\"AnimationPlayBackEvent\")}}\n- {{domxref(\"Animation.playState\")}}\n- {{domxref(\"CustomEvent.CustomEvent\", \"CustomEvent()\")}}\n- {{domxref(\"Event.Event\", \"Event()\")}}\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1542,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/htmlolistelement/index.md"},"content":{"kind":"string","value":"---\ntitle: HTMLOListElement\nslug: Web/API/HTMLOListElement\npage-type: web-api-interface\nbrowser-compat: api.HTMLOListElement\n---\n\n{{ APIRef(\"HTML DOM\") }}\n\nThe **`HTMLOListElement`** interface provides special properties (beyond those defined on the regular {{domxref(\"HTMLElement\")}} interface it also has available to it by inheritance) for manipulating ordered list elements.\n\n{{InheritanceDiagram}}\n\n## Instance properties\n\n_Inherits properties from its parent, {{domxref(\"HTMLElement\")}}._\n\n- {{domxref(\"HTMLOListElement.reversed\")}}\n - : A boolean value reflecting the [`reversed`](/en-US/docs/Web/HTML/Element/ol#reversed) and defining if the numbering is descending, that is its value is `true`, or ascending (`false`).\n- {{domxref(\"HTMLOListElement.start\")}}\n - : A `long` value reflecting the [`start`](/en-US/docs/Web/HTML/Element/ol#start) and defining the value of the first number of the first element of the list.\n- {{domxref(\"HTMLOListElement.type\")}}\n\n - : A string value reflecting the [`type`](/en-US/docs/Web/HTML/Element/ol#type) and defining the kind of marker to be used to display. It can have the following values:\n\n - `'1'` meaning that decimal numbers are used: `1`, `2`, `3`, `4`, `5`, …\n - `'a'` meaning that the lowercase latin alphabet is used: `a`, `b`, `c`, `d`, `e`, …\n - `'A'` meaning that the uppercase latin alphabet is used: `A`, `B`, `C`, `D`, `E`, …\n - `'i'` meaning that the lowercase latin numerals are used: `i`, `ii`, `iii`, `iv`, `v`, …\n - `'I'` meaning that the uppercase latin numerals are used: `I`, `II`, `III`, `IV`, `V`, …\n\n- {{domxref(\"HTMLOListElement.compact\")}} {{deprecated_inline}}\n - : A boolean value indicating that spacing between list items should be reduced. This property reflects the [`compact`](/en-US/docs/Web/HTML/Element/ol#compact) attribute only, it doesn't consider the {{cssxref(\"line-height\")}} CSS property used for that behavior in modern pages.\n\n## Instance methods\n\n_No specific method; inherits methods from its parent, {{domxref(\"HTMLElement\")}}._\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- The HTML element implementing this interface: {{ HTMLElement(\"ol\") }}.\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1543,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/navigation_api/index.md"},"content":{"kind":"string","value":"---\ntitle: Navigation API\nslug: Web/API/Navigation_API\npage-type: web-api-overview\nstatus:\n - experimental\nbrowser-compat:\n - api.Navigation\n - api.NavigationDestination\n - api.NavigationHistoryEntry\n - api.NavigationTransition\nspec-urls: https://html.spec.whatwg.org/multipage/nav-history-apis.html#navigation-api\n---\n\n{{SeeCompatTable}}{{DefaultAPISidebar(\"Navigation API\")}}\n\nThe **Navigation API** provides the ability to initiate, intercept, and manage browser navigation actions. It can also examine an application's history entries. This is a successor to previous web platform features such as the {{domxref(\"History API\", \"\", \"\", \"nocode\")}} and {{domxref(\"window.location\")}}, which solves their shortcomings and is specifically aimed at the needs of {{glossary(\"SPA\", \"single-page applications (SPAs)\")}}.\n\n## Concepts and usage\n\nIn SPAs, the page template tends to stay the same during usage, and the content is dynamically rewritten as the user visits different pages or features. As a result, only one distinct page is loaded in the browser, which breaks the expected user experience of navigating back and forth between different locations in the viewing history. This problem can be solved to a degree via the {{domxref(\"History API\", \"\", \"\", \"nocode\")}}, but it is not designed for the needs of SPAs. The Navigation API aims to bridge that gap.\n\nThe API is accessed via the {{domxref(\"Window.navigation\")}} property, which returns a reference to a global {{domxref(\"Navigation\")}} object. Each `window` object has its own corresponding `navigation` instance.\n\n### Handling navigations\n\nThe `navigation` interface has several associated events, the most notable being the {{domxref(\"Navigation/navigate_event\", \"navigate\")}} event. This is fired when [any type of navigation](https://github.com/WICG/navigation-api#appendix-types-of-navigations) is initiated, meaning that you can control all page navigations from one central place, ideal for routing functionality in SPA frameworks. (This is not the case with the {{domxref(\"History API\", \"\", \"\", \"nocode\")}}, where it is sometimes hard to figure out responding to all navigations.) The `navigate` event handler is passed a {{domxref(\"NavigateEvent\")}} object, which contains detailed information including details around the navigation's destination, type, whether it contains `POST` form data or a download request, and more.\n\nThe `NavigationEvent` object also provides two methods:\n\n- {{domxref(\"NavigateEvent.intercept\", \"intercept()\")}} takes as an argument a callback handler function returning a promise. It allows you to control what happens when the navigation is initiated. For example, in the case of an SPA, it can be used to load relevant new content into the UI based on the path of the URL navigated to.\n- {{domxref(\"NavigateEvent.scroll\", \"scroll()\")}} allows you to manually initiate the browser's scroll behavior (e.g. to a fragment identifier in the URL), if it makes sense for your code, rather than waiting for the browser to handle it automatically.\n\nOnce a navigation is initiated, and your `intercept()` handler is called, a {{domxref(\"NavigationTransition\")}} object instance is created (accessible via {{domxref(\"Navigation.transition\")}}), which can be used to track the process of the ongoing navigation.\n\n> **Note:** In this context \"transition\" refers to the transition between one history entry and another. It isn't related to CSS transitions.\n\n> **Note:** You can also call {{domxref(\"Event.preventDefault\", \"preventDefault()\")}} to stop the navigation entirely for most [navigation types](/en-US/docs/Web/API/NavigateEvent/navigationType#value); cancellation of traverse navigations is not yet implemented.\n\nWhen the `intercept()` handler function's promise fulfills, the `Navigation` object's {{domxref(\"Navigation/navigatesuccess_event\", \"navigatesuccess\")}} event fires, allowing you to run cleanup code after a successful navigation has completed. If it rejects, meaning the navigation has failed, {{domxref(\"Navigation/navigateerror_event\", \"navigateerror\")}} fires instead, allowing you to gracefully handle the failure case. There is also a {{domxref(\"NavigationTransition.finished\", \"finished\")}} property on the `NavigationTransition` object, which fulfills or rejects at the same time as the aforementioned events are fired, providing another path for handling the success and failure cases.\n\n> **Note:** Before the Navigation API was available, to do something similar you'd have to listen for all click events on links, run `e.preventDefault()`, perform the appropriate {{domxref(\"History.pushState()\")}} call, then set up the page view based on the new URL. And this wouldn't handle all navigations — only user-initiated link clicks.\n\n### Programmatically updating and traversing the navigation history\n\nAs the user navigates through your application, each new location navigated to results in the creation of a navigation history entry. Each history entry is represented by a distinct {{domxref(\"NavigationHistoryEntry\")}} object instance. These contain several properties such as the entry's key, URL, and state information. You can get the entry that the user is currently on right now using {{domxref(\"Navigation.currentEntry\")}}, and an array of all existing history entries using {{domxref(\"Navigation.entries()\")}}. Each `NavigationHistoryEntry` object has a {{domxref(\"NavigationHistoryEntry/dispose_event\", \"dispose\")}} event, which fires when the entry is no longer part of the browser history. For example, if the user navigates back three times, then navigates forward to somewhere else, those three history entries will be disposed of.\n\n> **Note:** The Navigation API only exposes history entries created in the current browsing context that have the same origin as the current page (e.g. not navigations inside embedded {{htmlelement(\"iframe\")}}s, or cross-origin navigations), providing an accurate list of all previous history entries just for your app. This makes traversing the history a much less fragile proposition than with the older {{domxref(\"History API\", \"\", \"\", \"nocode\")}}.\n\nThe `Navigation` object contains all the methods you'll need to update and traverse through the navigation history:\n\n- {{domxref(\"Navigation.navigate\", \"navigate()\")}} {{Experimental_Inline}}\n - : Navigates to a new URL, creating a new navigation history entry.\n- {{domxref(\"Navigation.reload\", \"reload()\")}} {{Experimental_Inline}}\n - : Reloads the current navigation history entry.\n- {{domxref(\"Navigation.back\", \"back()\")}} {{Experimental_Inline}}\n - : Navigates to the previous navigation history entry, if that is possible.\n- {{domxref(\"Navigation.forward\", \"forward()\")}} {{Experimental_Inline}}\n - : Navigates to the next navigation history entry, if that is possible.\n- {{domxref(\"Navigation.traverseTo\", \"traverseTo()\")}} {{Experimental_Inline}}\n - : Navigates to a specific navigation history entry identified by its key value, which is obtained via the relevant entry's {{domxref(\"NavigationHistoryEntry.key\")}} property.\n\nEach one of the above methods returns an object containing two promises — `{ committed, finished }`. This allows the invoking function to wait on taking further action until:\n\n- `committed` fulfills, meaning that the visible URL has changed and a new {{domxref(\"NavigationHistoryEntry\")}} has been created.\n- `finished` fulfills, meaning that all promises returned by your `intercept()` handler are fulfilled. This is equivalent to the {{domxref(\"NavigationTransition.finished\")}} promise fulfilling, when the {{domxref(\"Navigation/navigatesuccess_event\", \"navigatesuccess\")}} event fires, as mentioned earlier.\n- either one of the above promises rejects, meaning that the navigation has failed for some reason.\n\n### State\n\nThe Navigation API allows you to store state on each history entry. This is developer-defined information — it can be whatever you like. For example, you might want to store a `visitCount` property that records the number of times a view has been visited, or an object containing multiple properties related to UI state, so that state can be restored when a user returns to that view.\n\nTo get a {{domxref(\"NavigationHistoryEntry\")}}'s state, you call its {{domxref(\"NavigationHistoryEntry.getState\", \"getState()\")}} method. It is initially `undefined`, but when state information is set on the entry, it will return the previously-set state information.\n\nSetting state is a bit more nuanced. You can't retrieve the state value and then update it directly — the copy stored on the entry will not change. Instead, you update it while performing a {{domxref(\"Navigation.navigate\", \"navigate()\")}} or {{domxref(\"Navigation.reload\", \"reload()\")}} — each one of these optionally takes an options object parameter, which includes a `state` property containing the new state to set on the history entry. When these navigations commit, the state change will be automatically applied.\n\nIn some cases however, a state change will be independent from a navigation or reload — for example when a page contains an expandable/collapsible {{htmlelement(\"details\")}} element. In this case, you might want to store the expanded/collapsed state in your history entry, so you can restore it when the user returns to the page or restarts their browser. Cases like this are handled using {{domxref(\"Navigation.updateCurrentEntry()\")}}. The {{domxref(\"Navigation/currententrychange_event\", \"currententrychange\")}} will fire when the current entry change is complete.\n\n### Limitations\n\nThere are a few perceived limitations with the Navigation API:\n\n1. The current specification doesn't trigger a {{domxref(\"Navigation.navigate_event\", \"navigate\")}} event on a page's first load. This might be fine for sites that use Server Side Rendering (SSR)—your server could return the correct initial state, which is the fastest way to get content to your users. But sites that leverage client-side code to create their pages may need an additional function to initialize the page.\n2. The Navigation API operates only within a single frame—the top-level page, or a single specific {{htmlelement(\"iframe\")}}. This has some interesting implications that are [further documented in the spec](https://github.com/WICG/navigation-api#warning-backforward-are-not-always-opposites), but in practice, will reduce developer confusion. The previous {{domxref(\"History API\", \"\", \"\", \"nocode\")}} has several confusing edge cases, like support for frames, which the Navigation API handles up-front.\n3. You can't currently use the Navigation API to programmatically modify or rearrange the history list. It might be useful to have a temporary state, for example navigating the user to a temporary modal that asks them for some information, then going back to the previous URL. In this case, you'd want to delete the temporary modal navigation entry so the user cannot mess up the application flow by hitting the forward button and opening it again.\n\n## Interfaces\n\n- {{domxref(\"NavigateEvent\")}} {{Experimental_Inline}}\n - : Event object for the {{domxref(\"Navigation/navigate_event\", \"navigate\")}} event, which fires when [any type of navigation](https://github.com/WICG/navigation-api#appendix-types-of-navigations) is initiated. It provides access to information about that navigation, and most notably the {{domxref(\"NavigateEvent.intercept\", \"intercept()\")}}, which allows you to control what happens when the navigation is initiated.\n- {{domxref(\"Navigation\")}} {{Experimental_Inline}}\n - : Allows control over all navigation actions for the current `window` in one central place, including initiating navigations programmatically, examining navigation history entries, and managing navigations as they happen.\n- {{domxref(\"NavigationCurrentEntryChangeEvent\")}} {{Experimental_Inline}}\n - : Event object for the {{domxref(\"Navigation/currententrychange_event\", \"currententrychange\")}} event, which fires when the {{domxref(\"Navigation.currentEntry\")}} has changed. It provides access to the navigation type, and the previous history entry that was navigated from.\n- {{domxref(\"NavigationDestination\")}} {{Experimental_Inline}}\n - : Represents the destination being navigated to in the current navigation.\n- {{domxref(\"NavigationHistoryEntry\")}} {{Experimental_Inline}}\n - : Represents a single navigation history entry.\n- {{domxref(\"NavigationTransition\")}} {{Experimental_Inline}}\n - : Represents an ongoing navigation.\n\n## Extensions to other interfaces\n\n- {{domxref(\"Window.navigation\")}} {{ReadOnlyInline}} {{Experimental_Inline}}\n - : Returns the current `window`'s associated {{domxref(\"Navigation\")}} object. This is the entry point for the Navigation API.\n\n## Examples\n\n> **Note:** Check out Domenic Denicola's [Navigation API live demo](https://gigantic-honored-octagon.glitch.me/).\n\n### Handling a navigation using `intercept()`\n\n```js\nnavigation.addEventListener(\"navigate\", (event) => {\n // Exit early if this navigation shouldn't be intercepted,\n // e.g. if the navigation is cross-origin, or a download request\n if (shouldNotIntercept(event)) {\n return;\n }\n\n const url = new URL(event.destination.url);\n\n if (url.pathname.startsWith(\"/articles/\")) {\n event.intercept({\n async handler() {\n // The URL has already changed, so show a placeholder while\n // fetching the new content, such as a spinner or loading page\n renderArticlePagePlaceholder();\n\n // Fetch the new content and display when ready\n const articleContent = await getArticleContent(url.pathname);\n renderArticlePage(articleContent);\n },\n });\n }\n});\n```\n\n### Handling scrolling using `scroll()`\n\nIn this example of intercepting a navigation, the `handler()` function starts by fetching and rendering some article content, but then fetches and renders some secondary content afterwards. It makes sense to scroll the page to the main article content as soon as it is available so the user can interact with it, rather than waiting until the secondary content is also rendered. To achieve this, we have added a {{domxref(\"NavigateEvent.scroll\", \"scroll()\")}} call between the two.\n\n```js\nnavigation.addEventListener(\"navigate\", (event) => {\n if (shouldNotIntercept(event)) {\n return;\n }\n const url = new URL(event.destination.url);\n\n if (url.pathname.startsWith(\"/articles/\")) {\n event.intercept({\n async handler() {\n const articleContent = await getArticleContent(url.pathname);\n renderArticlePage(articleContent);\n\n event.scroll();\n\n const secondaryContent = await getSecondaryContent(url.pathname);\n addSecondaryContent(secondaryContent);\n },\n });\n }\n});\n```\n\n### Traversing to a specific history entry\n\n```js\n// On JS startup, get the key of the first loaded page\n// so the user can always go back there.\nconst { key } = navigation.currentEntry;\nbackToHomeButton.onclick = () => navigation.traverseTo(key);\n\n// Navigate away, but the button will always work.\nawait navigation.navigate(\"/another_url\").finished;\n```\n\n### Updating state\n\n```js\nnavigation.navigate(url, { state: newState });\n```\n\nOr\n\n```js\nnavigation.reload({ state: newState });\n```\n\nOr if the state is independent from a navigation or reload:\n\n```js\nnavigation.updateCurrentEntry({ state: newState });\n```\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- [Modern client-side routing: the Navigation API](https://developer.chrome.com/docs/web-platform/navigation-api/)\n- [Navigation API explainer](https://github.com/WICG/navigation-api/blob/main/README.md)\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1544,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/html_sanitizer_api/index.md"},"content":{"kind":"string","value":"---\ntitle: HTML Sanitizer API\nslug: Web/API/HTML_Sanitizer_API\npage-type: web-api-overview\nstatus:\n - experimental\nbrowser-compat: api.Sanitizer\n---\n\n{{DefaultAPISidebar(\"HTML Sanitizer API\")}}{{SeeCompatTable}}\n\n{{securecontext_header}}\n\n> **Warning:** This documentation reflects stale browser implementations.\n> The specification has changed significantly since the docs were written, and they will need to be updated once browser implementations catch up.\n\nThe **HTML Sanitizer API** allow developers to take untrusted strings of HTML and {{domxref('Document')}} or {{domxref('DocumentFragment')}} objects, and sanitize them for safe insertion into a document's DOM.\n\n## Concepts and usage\n\nWeb applications often need to work with untrusted HTML on the client side, for example, as part of a client-side templating solution or for rendering user generated content, or when including data in a frame from another site.\nThe Sanitizer API allows for rendering of this potentially untrusted HTML in a safe manner.\n\nTo access the API you would use the {{domxref('Sanitizer.Sanitizer()','Sanitizer()')}} constructor to create and configure a {{domxref('Sanitizer')}} instance.\nThe configuration options parameter allows you to specify the allowed and dis-allowed elements and attributes, and to enable custom elements and comments.\n\nThe most common use-case - preventing XSS - is handled by the default configuration.\nCreating a {{domxref(\"Sanitizer.Sanitizer\", \"Sanitizer()\")}} with a custom configuration is necessary only to handle additional, application-specific use cases.\n\nThe API has two main methods for sanitizing data:\n\n1. {{domxref('Element.setHTML()')}} parses and sanitizes a string of HTML and immediately inserts it into the DOM as a child of the current element.\n This is essentially a \"safe\" version of {{domxref('Element.innerHTML')}}, and should be used instead of `innerHTML` when inserting untrusted data.\n2. {{domxref('Sanitizer.sanitize()')}} sanitizes data that is in a {{domxref('Document')}} or {{domxref('DocumentFragment')}}. It might be used, for example, to sanitize a {{domxref('Document')}} instance in a frame.\n\n### Parsing and sanitizing strings\n\nThe result of parsing a string of HTML depends on the context/the element into which it is inserted.\n\nFor example, an HTML string containing {{HTMLElement(\"td\")}} elements is valid if inserted under a {{HTMLElement(\"table\")}} elements, but will be dropped if inserted in a {{HTMLElement(\"div\")}} element.\nSimilarly, an {{HTMLElement(\"em\")}} element is a valid node in a {{HTMLElement(\"div\")}} but the tag will be escaped if used in a {{HTMLElement(\"textarea\")}}:\n\n```html\n\n
bla
\n\n\n\n```\n\nThe target element must therefore be known when the parser is run and the resulting subtree must be inserted into that same type of element in the DOM, or the result will be incorrect.\nThis consideration does not matter for {{domxref('Element.setHTML()')}} as it is called on a particular element and the context is therefore implicit.\n\nThe parser may also perform normalization operations on the input string.\nAs a result, even if the HTML is valid and the sanitizer method does nothing, the sanitized output may not precisely match the unsanitized input.\nThis applies to both methods.\n\n## Interfaces\n\n- {{domxref('Sanitizer')}} {{Experimental_Inline}}\n - : Provides the functionality to define a sanitizer configuration, to sanitize untrusted strings of HTML for later insertion into the DOM, and to sanitize {{domxref('Document')}} and {{domxref('DocumentFragment')}} objects.\n- {{domxref('Element/setHTML','Element.setHTML()')}}\n - : Parses a string of HTML into a subtree of nodes, sanitizes it using a `Sanitizer` object, then sets it as a child of the current element.\n\n## Examples\n\nThe following examples show how to use the sanitizer API using the _default_ sanitizer (at time of writing configuration operations are not yet supported).\n\n### Sanitize a string immediately\n\nThe code below demonstrates how {{domxref('Element/setHTML','Element.setHTML()')}} is used to sanitize a string of HTML and insert it into the `Element` with an id of `target`.\n\nThe `script` element is disallowed by the default sanitizer so the alert is removed.\n\n```js\nconst unsanitized_string = \"abc \n\n \n \n \n Click on a shape to transform it\n \n\n```\n\nLive preview:\n\n{{EmbedLiveSample(\"Using_multiple_SVGTransform_objects\",300,280)}}\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1576,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/mediadevices/index.md"},"content":{"kind":"string","value":"---\ntitle: MediaDevices\nslug: Web/API/MediaDevices\npage-type: web-api-interface\nbrowser-compat: api.MediaDevices\n---\n\n{{APIRef(\"Media Capture and Streams\")}}{{SecureContext_Header}}\n\nThe **`MediaDevices`** interface of the {{domxref(\"Media Capture and Streams API\", \"\", \"\", \"nocode\")}} provides access to connected media input devices like cameras and microphones, as well as screen sharing. In essence, it lets you obtain access to any hardware source of media data.\n\n{{InheritanceDiagram}}\n\n## Instance properties\n\n_Inherits properties from its parent interface, {{domxref(\"EventTarget\")}}._\n\n## Instance methods\n\n_Inherits methods from its parent interface, {{domxref(\"EventTarget\")}}._\n\n- {{domxref(\"MediaDevices.enumerateDevices\", \"enumerateDevices()\")}}\n - : Obtains an array of information about the media input and output devices available on the system.\n- {{domxref(\"MediaDevices.getSupportedConstraints\", \"getSupportedConstraints()\")}}\n - : Returns an object conforming to {{domxref(\"MediaTrackSupportedConstraints\")}} indicating which constrainable properties are supported on the {{domxref(\"MediaStreamTrack\")}} interface. See [Media Streams API](/en-US/docs/Web/API/Media_Capture_and_Streams_API/Constraints) to learn more about constraints and how to use them.\n- {{domxref(\"MediaDevices.getDisplayMedia\", \"getDisplayMedia()\")}}\n - : Prompts the user to select a display or portion of a display (such as a window) to capture as a {{domxref(\"MediaStream\")}} for sharing or recording purposes. Returns a promise that resolves to a `MediaStream`.\n- {{domxref(\"MediaDevices.getUserMedia\", \"getUserMedia()\")}}\n - : With the user's permission through a prompt, turns on a camera and/or a microphone on the system and provides a {{domxref(\"MediaStream\")}} containing a video track and/or an audio track with the input.\n- {{domxref(\"MediaDevices.selectAudioOutput\", \"selectAudioOutput()\") }} {{Experimental_Inline}}\n - : Prompts the user to select a specific audio output device.\n\n## Events\n\n- {{domxref(\"MediaDevices/devicechange_event\", \"devicechange\")}}\n - : Fired when a media input or output device is attached to or removed from the user's computer.\n\n## Example\n\n```js\n// Put variables in global scope to make them available to the browser console.\nconst video = document.querySelector(\"video\");\nconst constraints = {\n audio: false,\n video: true,\n};\n\nnavigator.mediaDevices\n .getUserMedia(constraints)\n .then((stream) => {\n const videoTracks = stream.getVideoTracks();\n console.log(\"Got stream with constraints:\", constraints);\n console.log(`Using video device: ${videoTracks[0].label}`);\n stream.onremovetrack = () => {\n console.log(\"Stream ended\");\n };\n video.srcObject = stream;\n })\n .catch((error) => {\n if (error.name === \"OverconstrainedError\") {\n console.error(\n `The resolution ${constraints.video.width.exact}x${constraints.video.height.exact} px is not supported by your device.`,\n );\n } else if (error.name === \"NotAllowedError\") {\n console.error(\n \"You need to grant this page permission to access your camera and microphone.\",\n );\n } else {\n console.error(`getUserMedia error: ${error.name}`, error);\n }\n });\n```\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- [Media Capture and Streams API](/en-US/docs/Web/API/Media_Capture_and_Streams_API): The API this interface is part of.\n- [Screen Capture API](/en-US/docs/Web/API/Screen_Capture_API): The API defining the {{domxref(\"MediaDevices.getDisplayMedia\", \"getDisplayMedia()\")}} method.\n- [WebRTC API](/en-US/docs/Web/API/WebRTC_API)\n- {{domxref(\"Navigator.mediaDevices\")}}: Returns a reference to a `MediaDevices` object that can be used to access devices.\n- [CameraCaptureJS:](https://github.com/chrisjohndigital/CameraCaptureJS) HTML video capture and playback using `MediaDevices` and the MediaStream Recording API\n- [OpenLang](https://github.com/chrisjohndigital/OpenLang): HTML video language lab web application using `MediaDevices` and the MediaStream Recording API for video recording\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1577,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/mediadevices"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/mediadevices/getsupportedconstraints/index.md"},"content":{"kind":"string","value":"---\ntitle: \"MediaDevices: getSupportedConstraints() method\"\nshort-title: getSupportedConstraints()\nslug: Web/API/MediaDevices/getSupportedConstraints\npage-type: web-api-instance-method\nbrowser-compat: api.MediaDevices.getSupportedConstraints\n---\n\n{{APIRef(\"Media Capture and Streams\")}}{{SecureContext_Header}}\n\nThe **`getSupportedConstraints()`** method of the {{domxref(\"MediaDevices\")}} interface returns an object based on the {{domxref(\"MediaTrackSupportedConstraints\")}} dictionary, whose member fields each specify one of the constrainable properties the {{Glossary(\"user agent\")}} understands.\n\n## Syntax\n\n```js-nolint\ngetSupportedConstraints()\n```\n\n### Parameters\n\nNone.\n\n### Return value\n\nA new object based on the {{domxref(\"MediaTrackSupportedConstraints\")}} dictionary listing the constraints supported by the user agent.\nBecause only constraints supported by the user agent are included in the list, each of these Boolean properties has the value `true`.\n\n## Examples\n\nThis example outputs a list of the constraints supported by your browser.\n\n```html hidden\n

The following media constraints are supported by your browser:

\n\n
    \n```\n\n```css hidden\nbody {\n font:\n 15px Arial,\n sans-serif;\n}\n```\n\n```js\nconst constraintList = document.querySelector(\"#constraintList\");\nconst supportedConstraints = navigator.mediaDevices.getSupportedConstraints();\n\nfor (const constraint of Object.keys(supportedConstraints)) {\n const elem = document.createElement(\"li\");\n elem.innerHTML = `${constraint}`;\n constraintList.appendChild(elem);\n}\n```\n\n### Result\n\n{{ EmbedLiveSample('Examples', 600, 350) }}\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1578,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/mediadevices"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/mediadevices/selectaudiooutput/index.md"},"content":{"kind":"string","value":"---\ntitle: \"MediaDevices: selectAudioOutput() method\"\nshort-title: selectAudioOutput()\nslug: Web/API/MediaDevices/selectAudioOutput\npage-type: web-api-instance-method\nstatus:\n - experimental\nbrowser-compat: api.MediaDevices.selectAudioOutput\n---\n\n{{APIRef(\"Audio Output Devices API\")}}{{securecontext_header}}{{SeeCompatTable}}\n\nThe **`MediaDevices.selectAudioOutput()`** method of the [Audio Output Devices API](/en-US/docs/Web/API/Audio_Output_Devices_API) prompts the user to select an audio output device, such as a speaker or headset. If the user selects a device, the method grants user permission to use the selected device as an audio output sink.\n\nFollowing selection, if the device is available it can be enumerated using {{domxref(\"MediaDevices.enumerateDevices()\")}} and set as the audio output sink using {{domxref(\"HTMLMediaElement.setSinkId()\")}}.\n\nOn success, the returned {{jsxref(\"Promise\")}} is resolved with a {{domxref(\"MediaDeviceInfo\")}} describing the selected device.\n\n## Syntax\n\n```js-nolint\nselectAudioOutput()\nselectAudioOutput(options)\n```\n\n### Parameters\n\n- `options` {{Optional_Inline}}\n\n - : An object that configures what device(s) may be offered in the user prompt.\n\n - `deviceId` {{Optional_Inline}}\n\n - : A string representing the ID of a single previously exposed/permitted device.\n If not set, a prompt with all available audio output devices will be displayed.\n\n The option is intended for applications that want to store a device id so that the same device can be used by default in future sessions.\n Note that the method may return a new ID for the same device, and that persisted ids _must be passed_ through `selectAudioOutput()` successfully before they will work with {{domxref(\"HTMLMediaElement.setSinkId\",\"setSinkId()\")}}.\n\n > **Note:** A user agent may choose to skip prompting the user if a specified non-null id was previously exposed to the user by `selectAudioOutput()` in an earlier session.\n > In this case the user agent may simply resolve with this device id, or a new id for the same device if it has changed.\n > If permission for the specified device was previously granted but has since been revoked, the user-agent might display all allowed devices, highlighting the one with the specified ID.\n\n### Return value\n\nA {{ jsxref(\"Promise\") }} that is fulfilled with a {{domxref(\"MediaDeviceInfo\")}} object that describes the audio output device selected by the user.\n\n### Exceptions\n\n- `NotAllowedError` {{domxref(\"DOMException\")}}\n - : Returned if a [`speaker-selection`](/en-US/docs/Web/HTTP/Headers/Permissions-Policy/speaker-selection) [Permissions Policy](/en-US/docs/Web/HTTP/Permissions_Policy) is used to block use of audio outputs (in addition the popup for selecting an audio output won't be displayed), or the user closed the selection prompt without choosing a device.\n- `NotFoundError` {{domxref(\"DOMException\")}}\n - : Returned if there are no available audio output devices.\n- `InvalidStateError` {{domxref(\"DOMException\")}}\n - : Returned if there hasn't been a {{Glossary(\"transient activation\")}} (you must trigger it from some kind of UI event).\n\n## Security requirements\n\nAccess to the API is subject to the following constraints:\n\n- The method must be called in a [secure context](/en-US/docs/Web/Security/Secure_Contexts).\n- [Transient user activation](/en-US/docs/Web/Security/User_activation) is required.\n The user has to interact with the page or a UI element for this feature to work.\n- Access may be gated by the [`speaker-selection`](/en-US/docs/Web/HTTP/Headers/Permissions-Policy/midi) HTTP [Permission Policy](/en-US/docs/Web/HTTP/Permissions_Policy).\n\nThe permission status can be queried using the [Permissions API](/en-US/docs/Web/API/Permissions_API) method {{domxref(\"Permissions.query\", \"navigator.permissions.query()\")}}, passing a permission descriptor with the `speaker-selection` permission.\n\n## Examples\n\nHere's an example of using `selectAudioOutput()`, within a function that is triggered by a button click.\nIt outputs the selected {{domxref(\"MediaDeviceInfo.deviceId\", \"device IDs\", \"\", \"nocode\")}} and labels (if available) or an error message.\n\n```js\ndocument.querySelector(\"#myButton\").addEventListener(\"click\", () => {\n if (!navigator.mediaDevices.selectAudioOutput) {\n console.log(\"selectAudioOutput() not supported.\");\n return;\n }\n\n // Display prompt and log selected device or error\n navigator.mediaDevices\n .selectAudioOutput()\n .then((device) => {\n console.log(`${device.kind}: ${device.label} id = ${device.deviceId}`);\n })\n .catch((err) => {\n console.error(`${err.name}: ${err.message}`);\n });\n});\n```\n\nOn selection of an output this might produce:\n\n```bash\naudiooutput: Realtek Digital Output (Realtek(R) Audio) id = 0wE6fURSZ20H0N2NbxqgowQJLWbwo+5ablCVVJwRM3k=\n```\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n\n## See also\n\n- {{domxref(\"HTMLMediaElement.setSinkId()\")}}\n- {{domxref(\"HTMLMediaElement.sinkId\")}}\n- [WebRTC](/en-US/docs/Web/API/WebRTC_API) - the introductory page to the API\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1579,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/mediadevices"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/mediadevices/devicechange_event/index.md"},"content":{"kind":"string","value":"---\ntitle: \"MediaDevices: devicechange event\"\nshort-title: devicechange\nslug: Web/API/MediaDevices/devicechange_event\npage-type: web-api-event\nbrowser-compat: api.MediaDevices.devicechange_event\n---\n\n{{APIRef(\"Media Capture and Streams\")}}{{SecureContext_Header}}\n\nThe **`devicechange`** event is sent to a {{domxref(\"MediaDevices\")}} instance whenever a media device such as a camera, microphone, or speaker is connected to or removed from the system.\n\nThis event is not cancelable and does not bubble.\n\n## Syntax\n\nUse the event name in methods like {{domxref(\"EventTarget.addEventListener\", \"addEventListener()\")}}, or set an event handler property.\n\n```js\naddEventListener(\"devicechange\", (event) => {});\n\nondevicechange = (event) => {};\n```\n\n## Event type\n\nA generic {{domxref(\"Event\")}}.\n\n## Example\n\nIn this example, we create a function called `updateDeviceList()`, which is\ncalled once when {{domxref(\"MediaDevices.getUserMedia()\")}} successfully obtains a\nstream, and then is called any time the device list changes. It displays in the browser\nwindow two lists: one of audio devices and one of video devices, with both the device's\nlabel (name) and whether it's an input or an output device. Because the example provides\na handler for the `devicechange` event, the list is refreshed any time a\nmedia device is attached to or removed from the device running the sample.\n\n```html hidden\n

    Click the start button below to begin the demonstration.

    \n
    Start
    \n
    \n\n
    \n

    Audio devices:

    \n
      \n
      \n
      \n

      Video devices:

      \n
        \n
        \n\n\n```\n\n```css hidden\nbody {\n font:\n 14px \"Open Sans\",\n \"Arial\",\n sans-serif;\n}\n\nvideo {\n margin-top: 20px;\n border: 1px solid black;\n}\n\n.button {\n cursor: pointer;\n width: 160px;\n border: 1px solid black;\n font-size: 16px;\n text-align: center;\n padding-top: 2px;\n padding-bottom: 4px;\n color: white;\n background-color: darkgreen;\n}\n\nh2 {\n margin-bottom: 4px;\n}\n\n.left {\n float: left;\n width: 48%;\n margin-right: 2%;\n}\n\n.right {\n float: right;\n width: 48%;\n margin-left: 2%;\n}\n\n.deviceList {\n border: 1px solid black;\n list-style-type: none;\n margin-top: 2px;\n padding: 6px;\n}\n```\n\n```js hidden\n// UI elements\nconst videoElement = document.querySelector(\"#video\");\nconst logElement = document.querySelector(\"output\");\nconst startButton = document.querySelector(\"#startButton\");\n\nfunction log(msg) {\n logElement.innerHTML += `${msg}
        `;\n}\n\nstartButton.addEventListener(\n \"click\",\n () => {\n const constraints = {\n video: {\n width: 160,\n height: 120,\n frameRate: 30,\n },\n audio: {\n sampleRate: 44100,\n sampleSize: 16,\n volume: 0.25,\n },\n };\n\n navigator.mediaDevices\n .getUserMedia(constraints)\n .then((stream) => {\n videoElement.srcObject = stream;\n updateDeviceList();\n })\n .catch((err) => {\n log(`${err.name}: ${err.message}`);\n });\n },\n false,\n);\n```\n\nWe set up global variables that contain references to the {{HTMLElement(\"ul\")}}\nelements that are used to list the audio and video devices:\n\n```js\nconst audioList = document.getElementById(\"audioList\");\nconst videoList = document.getElementById(\"videoList\");\n```\n\n### Getting and drawing the device list\n\nNow let's take a look at `updateDeviceList()` itself. This method is called\nany time we want to fetch the current list of media devices and then update the\ndisplayed lists of audio and video devices using that information.\n\n```js\nfunction updateDeviceList() {\n navigator.mediaDevices.enumerateDevices().then((devices) => {\n audioList.innerHTML = \"\";\n videoList.innerHTML = \"\";\n\n devices.forEach((device) => {\n const elem = document.createElement(\"li\");\n const [kind, type, direction] = device.kind.match(/(\\w+)(input|output)/i);\n\n elem.innerHTML = `${device.label} (${direction})`;\n if (type === \"audio\") {\n audioList.appendChild(elem);\n } else if (type === \"video\") {\n videoList.appendChild(elem);\n }\n });\n });\n}\n```\n\n`updateDeviceList()` consists entirely of a call to the function\n{{domxref(\"MediaDevices.enumerateDevices\", \"enumerateDevices()\")}} on the\n{{domxref(\"MediaDevices\")}} object referenced in the\n{{domxref(\"navigator.mediaDevices\")}} property, as well as the code that's run when the\n{{jsxref(\"promise\")}} returned by `enumerateDevices()` is fulfilled. The\nfulfillment handler is called when the device list is ready. The list is passed into the\nfulfillment handler as an array of {{domxref(\"MediaDeviceInfo\")}} objects, each\ndescribing one media input or output device.\n\nA {{jsxref(\"Array.forEach\", \"forEach()\")}} loop is used to scan through all the\ndevices. For each device, we create a new {{HTMLElement(\"li\")}} object to be used to\ndisplay it to the user.\n\nThe line\n`let [kind, type, direction] = device.kind.match(/(\\w+)(input|output)/i);`\ndeserves special notice. This uses [destructuring assignment](/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) to assign the values of the first three items in the array returned by\n{{jsxref(\"String.match()\")}} to the variables `kind`, `type`, and\n`direction`. We do this because the value of\n{{domxref(\"MediaDeviceInfo.kind\")}} is a single string that includes both the media type\nand the direction the media flows, such as \"audioinput\" or \"videooutput\". This line,\nthen, pulls out the type (\"audio\" or \"video\") and direction (\"input\" or \"output\") so\nthey can be used to construct the string displayed in the list.\n\nOnce the string is assembled, containing the device's name in bold and the direction in\nparentheses, it's appended to the appropriate list by calling\n{{domxref(\"Node.appendChild\", \"appendChild()\")}} on either `audioList` or\n`videoList`, as appropriate based on the device type.\n\n### Handling device list changes\n\nWe call `updateDeviceList()` in two places. The first is in the\n{{domxref(\"MediaDevices.getUserMedia\", \"getUserMedia()\")}} promise's fulfillment\nhandler, to initially fill out the list when the stream is opened. The second is in the\nevent handler for this `devicechange` event:\n\n```js\nnavigator.mediaDevices.ondevicechange = (event) => {\n updateDeviceList();\n};\n```\n\nWith this code in place, each time the user plugs in a camera, microphone, or other\nmedia device, or turns one on or off, we call `updateDeviceList()` to redraw\nthe list of connected devices.\n\n### Result\n\n{{ EmbedLiveSample('Example', 600, 460, \"\", \"\", \"\", \"camera;microphone\") }}\n\n## Specifications\n\n{{Specifications}}\n\n## Browser compatibility\n\n{{Compat}}\n"},"__index_level_0__":{"kind":"number","value":0,"string":"0"}}},{"rowIdx":1580,"cells":{"repo_id":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/mediadevices"},"file_path":{"kind":"string","value":"data/mdn-content/files/en-us/web/api/mediadevices/getusermedia/index.md"},"content":{"kind":"string","value":"---\ntitle: \"MediaDevices: getUserMedia() method\"\nshort-title: getUserMedia()\nslug: Web/API/MediaDevices/getUserMedia\npage-type: web-api-instance-method\nbrowser-compat: api.MediaDevices.getUserMedia\n---\n\n{{securecontext_header}}{{APIRef(\"Media Capture and Streams\")}}\n\nThe **`getUserMedia()`** method of the {{domxref(\"MediaDevices\")}} interface prompts the user for permission to use a media input which produces a {{domxref(\"MediaStream\")}} with tracks containing the requested types of media.\n\nThat stream can include, for example, a video track (produced by either a hardware or virtual video source such as a camera, video recording device, screen sharing service, and so forth), an audio track (similarly, produced by a physical or virtual audio source like a microphone, A/D converter, or the like), and possibly other track types.\n\nIt returns a {{jsxref(\"Promise\")}} that resolves to a {{domxref(\"MediaStream\")}} object.\nIf the user denies permission, or matching media is not available, then the promise is rejected with `NotAllowedError` or `NotFoundError` {{domxref(\"DOMException\")}} respectively.\n\n> **Note:** It's possible for the returned promise to _neither_ resolve nor reject, as the user is not required to make a choice at all and may ignore the request.\n\n## Syntax\n\n```js-nolint\ngetUserMedia(constraints)\n```\n\n### Parameters\n\n- `constraints`\n\n - : An object specifying the types of media to\n request, along with any requirements for each type.\n\n The `constraints` parameter is an object with two members: `video` and\n `audio`, describing the media types requested. Either or both must be\n specified. If the browser cannot find all media tracks with the specified types that\n meet the constraints given, then the returned promise is rejected with\n `NotFoundError` {{domxref(\"DOMException\")}}.\n\n For both `video` and `audio`, its value is either a boolean or an object. The default value is `false`.\n\n - If `true` is specified for a media type, the resulting stream is _required_ to have that type of track in it. If one cannot be included for any reason, the returned promise will reject.\n - If `false` is specified for a media type, the resulting stream _must not_ have that type of track, or the returned promise will reject. Because both `video` and `audio` default to `false`, if the `constraints` object contains neither property or if it's not present at all, the returned promise will always reject.\n - If an object is specified for a media type, the object is read as a {{domxref(\"MediaTrackConstraints\")}} dictionary.\n\n### Return value\n\nA {{jsxref(\"Promise\")}} whose fulfillment handler receives a {{domxref(\"MediaStream\")}}\nobject when the requested media has successfully been obtained.\n\n### Exceptions\n\n- `AbortError` {{domxref(\"DOMException\")}}\n\n - : Although the user and operating system both granted access to the hardware device,\n and no hardware issues occurred that would cause a `NotReadableError` {{domxref(\"DOMException\")}}, throw if some\n problem occurred which prevented the device from being used.\n\n- `InvalidStateError` {{domxref(\"DOMException\")}}\n\n - : Thrown if current document is not fully active.\n\n- `NotAllowedError` {{domxref(\"DOMException\")}}\n\n - : Thrown if one or more of the requested source devices cannot be used at this time. This will\n happen if the browsing context is insecure (that is, the page was loaded using HTTP\n rather than HTTPS). It also happens if the user has specified that the current\n browsing instance is not permitted access to the device, the user has denied access\n for the current session, or the user has denied all access to user media devices\n globally. On browsers that support managing media permissions with [Permissions Policy](/en-US/docs/Web/HTTP/Permissions_Policy), this error is\n returned if Permissions Policy is not configured to allow access to the input source(s).\n\n > **Note:** Older versions of the specification used `SecurityError`\n > for this instead; `SecurityError` has taken on a new meaning.\n\n- `NotFoundError` {{domxref(\"DOMException\")}}\n - : Thrown if no media tracks of the type specified were found that satisfy the given constraints.\n- `NotReadableError` {{domxref(\"DOMException\")}}\n - : Thrown if, although the user granted permission to use the matching devices, a hardware error\n occurred at the operating system, browser, or Web page level which prevented access to\n the device.\n- `OverconstrainedError` {{domxref(\"DOMException\")}}\n\n - : Thrown if the specified constraints resulted in no candidate devices which met the criteria\n requested. The error is an object of type `OverconstrainedError`, and has a\n `constraint` property whose string value is the name of a constraint which\n was impossible to meet, and a `message` property containing a\n human-readable string explaining the problem.\n\n > **Note:** Because this error can occur even when the user has not yet granted\n > permission to use the underlying device, it can potentially be used as a\n > [fingerprinting](/en-US/docs/Glossary/Fingerprinting) surface.\n\n- `SecurityError` {{domxref(\"DOMException\")}}\n - : Thrown if user media support is disabled on the {{domxref(\"Document\")}} on which\n `getUserMedia()` was called. The mechanism by which user media support is\n enabled and disabled is left up to the individual user agent.\n- {{jsxref(\"TypeError\")}}\n - : Thrown if the list of constraints specified is empty, or has all constraints set to\n `false`. This can also happen if you try to call\n `getUserMedia()` in an insecure context, since\n {{domxref(\"navigator.mediaDevices\")}} is `undefined` in an insecure\n context.\n\n## Privacy and security\n\nAs an API that may involve significant privacy concerns, `getUserMedia()`'s\nspecification lays out a wide array of privacy and security requirements that browsers\nare obligated to meet.\n\n`getUserMedia()` is a powerful feature that can only be used in [secure contexts](/en-US/docs/Web/Security/Secure_Contexts); in insecure\ncontexts, `navigator.mediaDevices` is `undefined`, preventing\naccess to `getUserMedia()`. A secure context is, in short, a page loaded\nusing HTTPS or the `file:///` URL scheme, or a page loaded from\n`localhost`.\n\nIn addition, user permission is always required to access the user's audio and video\ninputs. Only a window's top-level document context for a valid origin can even request\npermission to use `getUserMedia()`, unless the top-level context expressly\ngrants permission for a given {{HTMLElement(\"iframe\")}} to do so using [Permissions Policy](/en-US/docs/Web/HTTP/Permissions_Policy). Otherwise, the user\nwill never even be asked for permission to use the input devices.\n\nFor additional details on these requirements and rules, how they are reflected in the\ncontext in which your code is running, and about how browsers manage user privacy and\nsecurity issues, read on.\n\n### User privacy\n\nAs an API that may involve significant privacy concerns, `getUserMedia()` is\nheld by the specification to very specific requirements for user notification and\npermission management. First, `getUserMedia()` must always get user\npermission before opening any media gathering input such as a webcam or microphone.\nBrowsers may offer a once-per-domain permission feature, but they must ask at least the\nfirst time, and the user must specifically grant ongoing permission if they choose to do\nso.\n\nOf equal importance are the rules around notification. Browsers are required to display\nan indicator that shows that a camera or microphone is in use, above and beyond any\nhardware indicator that may exist. They must also show an indicator that permission has\nbeen granted to use a device for input, even if the device is not actively recording at\nthe moment.\n\nFor example in Firefox, the URL bar displays a pulsing red icon to indicate that\nrecording is underway. The icon is gray if the permission is in place but recording is\nnot currently underway. The device's physical light is used to indicate whether or not\nrecording is currently active. If you've muted your camera (so-called \"facemuting\"),\nyour camera's activity light goes out to indicate that the camera is not actively\nrecording you, without discarding the permission to resume using the camera once muting\nis over.\n\n### Security\n\nThere are a number of ways security management and controls in a {{Glossary(\"user agent\")}} can cause `getUserMedia()` to return a security-related error.\n\n#### Permissions Policy\n\nThe two [Permissions Policy](/en-US/docs/Web/HTTP/Permissions_Policy) directives that apply to `getUserMedia()` are `camera`\nand `microphone`.\n\nFor example, this HTTP header will enable use of a camera by the document\nand any embedded {{HTMLElement(\"iframe\")}} elements that are loaded from the same\norigin:\n\n```http\nPermissions-Policy: camera=(self)\n```\n\nThis will request access to the microphone for the current origin and the specific\norigin `https://developer.mozilla.org`:\n\n```http\nPermissions-Policy: microphone=(self \"https://developer.mozilla.org\")\n```\n\nIf you're using `getUserMedia()` within an `\n```\n\n#### Encryption based security\n\nThe `getUserMedia()` method is only available in [secure contexts](/en-US/docs/Web/Security/Secure_Contexts). A secure context\nis one the browser is reasonably confident contains a document which was loaded\nsecurely, using HTTPS/TLS, and has limited exposure to insecure contexts. If a document\nisn't loaded in a secure context, the {{domxref(\"navigator.mediaDevices\")}} property is\n`undefined`, making access to `getUserMedia()` impossible.\n\nAttempting to access `getUserMedia()` in this situation will result in a\n{{jsxref(\"TypeError\")}}.\n\n#### Document source security\n\nBecause of the obvious security concern associated with `getUserMedia()` if\nused unexpectedly or without security being carefully managed, it can only be used in\nsecure contexts. There are a number of insecure ways to load a document that might, in\nturn, attempt to call `getUserMedia()`. The following are examples of\nsituations in which `getUserMedia()` is not permitted to be called:\n\n- A document loaded into a sandboxed {{HTMLElement(\"iframe\")}} element cannot call\n `getUserMedia()` unless the `