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

250
Visualizações
Inline scripts in new window from Javascript using window.open()

This has been asked before, and all the answer I could find are outdated, and do not work. This is a user side script injected (via Tampermonkey) into an existing web page, that creates an 'options' dialog, which requires JS to process selections made on that dialog, the 'dialog' being a new window. I have stripped it down to essentials.

Call to create the new window:

    function createConfigDiv() {
        let x = window.open();
        x.document.write(optionsHtml);
        x.document.close();
    }

optionsHtml is a global, created in a function so I can use code collapse, it is:

const optionsHtml = loadSimpleOptionsPage();
function loadSimpleOptionsPage() {
        let CSP = `<meta http-equiv=Content-Security-Policy content="script-src 'self' 'unsafe-inline';">`;
        let html =
            `<html>` +
                `<head>`+ CSP + `</head>` +
                `<script language="JavaScript" type="text/javascript">var i=0;</script>` +
            `</html>`;

        return html;
    }

It's structured that way so I can comment out the <script> block. Commenting it out means it all works as expected (a new tab, but no functionality) regardless of if I have any actual JS code in the block.

Rendered HTML:

rendered HTML

Error:

error

In a nutshell, "​Refused to execute inline script because it violates the following Content Security Policy directive: "script-src '..."

I assume the CSP it is displaying is from the page where my script, that opens the windows, is running from - that I have no control over. It is running at torn.com

The real code is a handler for an input element (checkbox). I can't really move it to an external file, this is being generated on the fly with no where to host it. I had tried writing into an iframe, resulting in the same error.

It seems that wherever the CSP referenced is coming from, it over-rides my meta tag. If I intentionally put a syntax error in my meta tag, I do get an error. As mentioned in the Chrome testing of header vs meta tag CSP directives, seems the last directive seen can only strengthen, not reduce (or replace), the security policy.

So I see a few options, none of which I could find/implement - open a new window with no CSP until I add it in a meta tag, another method besides using window.open() to do what I want, ??? Any suggestions appreciated!

about 4 years ago · Juan Pablo Isaza
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