支持的 DOM API

Web Worker 执行在与当前 window 不同的另一个全局上下文中,DOM 操作的 API 都需要在 worker 内部实现,当前支持以下列表的 API:

API 是否支持 备注
Attr.name ✔️ -
Attr.namespaceURI ✔️ -
Attr.value ✔️ -
CDATASection ✔️ 参考:Text
CharacterData.data ✔️ -
CharacterData.length ✔️ -
ChildNode.remove() ✔️ 实现在 Node 层级
ChildNode.replaceWith() ✔️ 实现在 Node 层级
Comment ✔️ 参考:CharacterDataNode
CSSStyleDeclaration.cssText ✔️ -
CSSStyleDeclaration.getPropertyValue() ✔️ -
CSSStyleDeclaration.removeProperty() ✔️ -
CSSStyleDeclaration.setProperty() ✔️ -
Document.body ✔️ -
Document.createComment() ✔️ -
Document.createDocumentFragment() ✔️ -
Document.createElement() ✔️ -
Document.createElementNS() ✔️ -
Document.createEvent() ✔️ -
Document.createTextNode() ✔️ -
Document.defaultView ✔️ -
Document.documentElement ✔️ -
document.getElementById(String id) ✔️ -
Document.getElementsByClassName() ✔️ -
document.getElementsByName() ✔️ -
Document.getElementsByTagName() ✔️ -
document.querySelector() ✔️ -
document.querySelectorAll() ✔️ -
DocumentFragment.getElementById() ✔️ -
DocumentFragment.querySelector() ✔️ 部分支持
DocumentFragment.querySelectorAll() ✔️ 部分支持
DOMImplementation.createDocument() ✔️ -
DOMSTokenList.length ✔️ -
DOMTokenList.add() ✔️ -
DOMTokenList.contains() ✔️ -
DOMTokenList.item() ✔️ -
DOMTokenList.remove() ✔️ -
DOMTokenList.replace() ✔️ -
DOMTokenList.toggle() ✔️ -
DOMTokenList.value ✔️ -
Element.attributes ✔️ -
Element.classList ✔️ -
Element.className ✔️ -
Element.getAttribute() ✔️ -
Element.getAttributeNS() ✔️ -
Element.getElementsByClassName() ✔️ -
Element.getElementsByTagName() ✔️ -
Element.hasAttribute() ✔️ -
Element.hasAttributeNS() ✔️ -
Element.hasAttributes() ✔️ -
Element.id ✔️ -
Element.innerHTML ✔️ 部分支持
Element.localName ✔️ -
Element.namespaceURI ✔️ -
Element.outerHTML ✔️ -
Element.querySelector() ✔️ 部分支持
Element.querySelectorAll() ✔️ 部分支持
Element.removeAttribute() ✔️ -
Element.removeAttributeNS() ✔️ -
Element.scrollIntoView() ✔️ 不支持带参数
Element.setAttribute() ✔️ -
Element.setAttributeNS() ✔️ -
Event.bubbles ✔️ -
Event.cancelable ✔️ -
Event.cancelBubble ✔️ -
Event.currentTarget ✔️ -
Event.eventPhase ✔️ -
Event.isTrusted ✔️ -
Event.returnValue ✔️ -
Event.target ✔️ -
Event.timeStamp ✔️ -
Event.type ✔️ -
EventTarget.addEventListener() ✔️ -
EventTarget.removeEventListener() ✔️ -
HTMLAnchorElement.hreflang ✔️ -
HTMLAnchorElement.media ✔️ -
HTMLAnchorElement.rel ✔️ -
HTMLAnchorElement.relList ✔️ -
HTMLAnchorElement.target ✔️ -
HTMLAnchorElement.text ✔️ -
HTMLAnchorElement.type ✔️ -
HTMLButtonElement.autofocus ✔️ -
HTMLButtonElement.disabled ✔️ -
HTMLButtonElement.formAction ✔️ -
HTMLButtonElement.formEnctype ✔️ -
HTMLButtonElement.formMethod ✔️ -
HTMLButtonElement.formTarget ✔️ -
HTMLButtonElement.name ✔️ -
HTMLButtonElement.type ✔️ -
HTMLButtonElement.value ✔️ -
HTMLDataElement.value ✔️ -
HTMLDataListElement.options ✔️ -
HTMLElement.accessKey ✔️ -
HTMLElement.accessKeyLabel ✔️ -
HTMLElement.async ✔️ -
HTMLElement.charset ✔️ -
HTMLElement.click() ✔️ -
HTMLElement.contentEditable ✔️ -
HTMLElement.crossOrigin ✔️ -
HTMLElement.defaultSelected ✔️ -
HTMLElement.defer ✔️ -
HTMLElement.dir ✔️ -
HTMLElement.disabled ✔️ -
HTMLElement.draggable ✔️ -
HTMLElement.form ✔️ -
HTMLElement.hidden ✔️ -
HTMLElement.index ✔️ -
HTMLElement.label ✔️ -
HTMLElement.lang ✔️ -
HTMLElement.noModule ✔️ -
HTMLElement.selected ✔️ -
HTMLElement.spellcheck ✔️ -
HTMLElement.src ✔️ -
HTMLElement.text ✔️ -
HTMLElement.translate ✔️ -
HTMLElement.type ✔️ -
HTMLElement.value ✔️ -
HTMLEmbedElement.height ✔️ -
HTMLEmbedElement.src ✔️ -
HTMLEmbedElement.type ✔️ -
HTMLEmbedElement.width ✔️ -
HTMLFieldSetElement.disabled ✔️ -
HTMLFieldSetElement.name ✔️ -
HTMLFormElement.acceptCharset ✔️ -
HTMLFormElement.action ✔️ -
HTMLFormElement.autocapitalize ✔️ -
HTMLFormElement.autocomplete ✔️ -
HTMLFormElement.elements ✔️ -
HTMLFormElement.length ✔️ -
HTMLFormElement.encoding or HTMLFormElement.enctype ✔️ -
HTMLFormElement.method ✔️ -
HTMLFormElement.name ✔️ -
HTMLFormElement.target ✔️ -
HTMLHyperlinkElementUtils.href ✔️ -
HTMLIFrameElement.allow ✔️ -
HTMLIFrameElement.allowfullscreen ✔️ -
HTMLIFrameElement.csp ✔️ -
HTMLIFrameElement.height ✔️ -
HTMLIFrameElement.name ✔️ -
HTMLIFrameElement.referrerPolicy ✔️ -
HTMLIFrameElement.src ✔️ -
HTMLIFrameElement.srcdoc ✔️ -
HTMLIFrameElement.width ✔️ -
HTMLImageElement.alt ✔️ -
HTMLImageElement.crossOrigin ✔️ -
HTMLImageElement.height ✔️ -
HTMLImageElement.isMap ✔️ -
HTMLImageElement.sizes ✔️ -
HTMLImageElement.src ✔️ -
HTMLImageElement.srcset ✔️ -
HTMLImageElement.useMap ✔️ -
HTMLImageElement.width ✔️ -
HTMLInputElement.accept ✔️ -
HTMLInputElement.accessKey ✔️ -
HTMLInputElement.alt ✔️ -
HTMLInputElement.autocapitalize ✔️ -
HTMLInputElement.autocomplete ✔️ -
HTMLInputElement.autofocus ✔️ -
HTMLInputElement.blur() ✔️ -
HTMLInputElement.defaultChecked ✔️ -
HTMLInputElement.defaultValue ✔️ -
HTMLInputElement.dirName ✔️ -
HTMLInputElement.disabled ✔️ -
HTMLInputElement.focus() ✔️ -
HTMLInputElement.form ✔️ -
HTMLInputElement.formAction ✔️ -
HTMLInputElement.formEncType ✔️ -
HTMLInputElement.formMethod ✔️ -
HTMLInputElement.formTarget ✔️ -
HTMLInputElement.height ✔️ -
HTMLInputElement.labels ✔️ -
HTMLInputElement.max ✔️ -
HTMLInputElement.maxLength ✔️ -
HTMLInputElement.min ✔️ -
HTMLInputElement.multiple ✔️ -
HTMLInputElement.name ✔️ -
HTMLInputElement.pattern ✔️ -
HTMLInputElement.placeholder ✔️ -
HTMLInputElement.required ✔️ -
HTMLInputElement.select() ✔️ -
HTMLInputElement.size ✔️ -
HTMLInputElement.src ✔️ -
HTMLInputElement.step ✔️ -
HTMLInputElement.type ✔️ -
HTMLInputElement.value ✔️ -
HTMLInputElement.valueAsDate ✔️ -
HTMLInputElement.valueAsNumber ✔️ -
HTMLInputElement.width ✔️ -
HTMLLabelElement.control ✔️ -
HTMLLabelElement.form ✔️ -
HTMLLabelElement.htmlFor ✔️ -
HTMLLinkElement.as ✔️ -
HTMLLinkElement.crossOrigin ✔️ -
HTMLLinkElement.disabled ✔️ -
HTMLLinkElement.href ✔️ -
HTMLLinkElement.hreflang ✔️ -
HTMLLinkElement.media ✔️ -
HTMLLinkElement.referrerPolicy ✔️ -
HTMLLinkElement.sizes ✔️ -
HTMLLinkElement.type ✔️ -
HTMLMapElement.areas ✔️ -
HTMLMapElement.name ✔️ -
HTMLMeterElement.high ✔️ -
HTMLMeterElement.labels ✔️ -
HTMLMeterElement.low ✔️ -
HTMLMeterElement.max ✔️ -
HTMLMeterElement.min ✔️ -
HTMLMeterElement.optimum ✔️ -
HTMLMeterElement.values ✔️ -
HTMLModElement.cite ✔️ -
HTMLModElement.datetime ✔️ -
HTMLOListElement.reversed ✔️ -
HTMLOListElement.start ✔️ -
HTMLOListElement.type ✔️ -
HTMLProgressElement.max ✔️ -
HTMLProgressElement.position ✔️ -
HTMLProgressElement.value ✔️ -
HTMLQuoteElement.cite ✔️ -
HTMLSelectElement.form ✔️ -
HTMLSelectElement.length ✔️ -
HTMLSelectElement.multiple ✔️ -
HTMLSelectElement.name ✔️ -
HTMLSelectElement.options ✔️ -
HTMLSelectElement.required ✔️ -
HTMLSelectElement.selectedIndex ✔️ -
HTMLSelectElement.selectedOptions ✔️ -
HTMLSelectElement.size ✔️ -
HTMLSelectElement.type ✔️ -
HTMLSelectElement.value ✔️ -
HTMLSourceElement.media ✔️ -
HTMLSourceElement.sizes ✔️ -
HTMLSourceElement.src ✔️ -
HTMLSourceElement.srcset ✔️ -
HTMLSourceElement.type ✔️ -
HTMLStyleElement.media ✔️ -
HTMLStyleElement.type ✔️ -
HTMLTableCellElement.abbr ✔️ -
HTMLTableCellElement.cellIndex ✔️ -
HTMLTableCellElement.colSpan ✔️ -
HTMLTableCellElement.headers ✔️ -
HTMLTableCellElement.rowSpan ✔️ -
HTMLTableCellElement.scope ✔️ -
HTMLTableColElement.span ✔️ -
HTMLTableElement.caption ✔️ -
HTMLTableElement.rows ✔️ -
HTMLTableElement.tBodies ✔️ -
HTMLTableElement.tFoot ✔️ -
HTMLTableElement.tHead ✔️ -
HTMLTableRowElement.cells ✔️ -
HTMLTableRowElement.deleteCell() ✔️ -
HTMLTableRowElement.insertCell() ✔️ -
HTMLTableRowElement.rowIndex ✔️ -
HTMLTableRowElement.sectionRowIndex ✔️ -
HTMLTableSectionElement.deleteRow() ✔️ -
HTMLTableSectionElement.insertRow() ✔️ -
HTMLTableSectionElement.rows ✔️ -
HTMLTimeElement.dateTime ✔️ -
MutationObserver.disconnect() ✔️ -
MutationObserver.observe() ✔️ -
MutationObserver.takeRecords() ✔️ -
MutationRecord.addedNodes ✔️ -
MutationRecord.attributeName ✔️ -
MutationRecord.attributeNamespace ✔️ -
MutationRecord.nextSibling ✔️ -
MutationRecord.oldValue ✔️ -
MutationRecord.previousSibling ✔️ -
MutationRecord.removedNodes ✔️ -
MutationRecord.target ✔️ -
MutationRecord.type ✔️ -
Node.appendChild() ✔️ -
Node.childNodes ✔️ -
Node.cloneNode() ✔️ 仅支持 Element 层级
Node.contains() ✔️ -
Node.firstChild ✔️ -
Node.hasChildNodes() ✔️ -
Node.insertBefore() ✔️ -
Node.isConnected ✔️ -
Node.lastChild ✔️ -
Node.nextSibling ✔️ -
Node.nodeName ✔️ -
Node.nodeType ✔️ -
Node.nodeValue ✔️ 仅支持 Element 层级
Node.ownerDocument ✔️ -
Node.parentElement ✔️ -
Node.parentNode ✔️ -
Node.previousSibling ✔️ -
Node.removeChild() ✔️ -
Node.replaceChild() ✔️ -
Node.textContent ✔️ -
NonDocumentTypeChildNode.nextElementSibling ✔️ -
NonDocumentTypeChildNode.previousElementSibling ✔️ -
ParentNode.childElementCount ✔️ -
ParentNode.children ✔️ -
ParentNode.firstElementChild ✔️ -
ParentNode.lastElementChild ✔️ -
ParentNode.querySelector() ✔️ 部分支持
ParentNode.querySelectorAll() ✔️ 部分支持
URL.href ✔️ -
Window.localStorage ✔️ -
Window.open() ✔️ -
Window.outerHeight ✔️ -
Window.outerWidth ✔️ -
Window.pageXOffset ✔️ -
Window.pageYOffset ✔️ -
Window.scroll() ✔️ -
Window.scrollTo() ✔️ -
Window.scrollX ✔️ -
Window.scrollY ✔️ -
Window.sessionStorage ✔️ -

注意:当前的 querySelectorquerySelectorAll 仅支持简单的选择器,例如:ID、类、元素或属性选择器。

本页目录