Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
The File System Access API file writing gives error

When i run the following program:

JS:

async function write(){
  const filehandle = window.showOpenFilePicker();
  const writable = await filehandle.createWritable();
  await writable.write('The file has been updated');
  await writable.close();
}

HTML:

<button onclick = "write();">
write file
</button>

I get the following error:

[Violation] Avoid using document.write(). https://developers.google.com/web/updates/2016/08/removing-document-write

I clicked the link and it was no help, and i got the same error when using document.append, even though document.write was not used.

I'm still a newbie to the File System Access API, and need help. Thank you all!

Edit: i have found out that naming a function 'write' is enough to trigger the document.write detection, but even after renaming the function, i now get the error:

Uncaught (in promise) TypeError: filehandle.createWritable is not a function

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The window.showOpenFilePicker() method returns a promise with an array of file handles according to the docs:

This means you should fulfill the promise (using await or chaining it with a then:

async function write(){
  const filehandle = await window.showOpenFilePicker();
  // rest of code...
}

Other than that, showOpenFilePicker returns an array containing the file handles. It needs to be retrieved from the array before you can create a writable. You can use array destructuring to do exactly that:

async function write(){
  const [filehandle] = await window.showOpenFilePicker();
  const writable = await filehandle.createWritable();
  await writable.write('The file has been updated');
  await writable.close();
}

And that should do the trick.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda