Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Automator运行带Safari的JavaScript时出现安全策略错误_Javascript_Content Security Policy_Automator_Security Policy - Fatal编程技术网

Automator运行带Safari的JavaScript时出现安全策略错误

Automator运行带Safari的JavaScript时出现安全策略错误,javascript,content-security-policy,automator,security-policy,Javascript,Content Security Policy,Automator,Security Policy,我正在使用以下自动机脚本: on run {input, parameters} set updateCount to 0 read (item 1 of input) set ps to paragraphs of the result set tot to count ps set TLFile to (("Users:Admin:Desktop:") as text) & "titleList.txt" set TLLines to

我正在使用以下自动机脚本:

on run {input, parameters}
    set updateCount to 0
    read (item 1 of input)
    set ps to paragraphs of the result
    set tot to count ps
    set TLFile to (("Users:Admin:Desktop:") as text) & "titleList.txt"
    set TLLines to paragraphs of (read file TLFile as «class utf8»)
    set descFile to (("Users:Admin:Desktop:") as text) & "descList.txt"
    set DescLines to paragraphs of (read file descFile as «class utf8»)
    tell application "Safari"
        reopen
        activate
    end tell
    repeat with i from 1 to tot
        set p to item i of ps
        if p is not "" then
            try
                tell application "Safari"
                    tell front window
                        set r to make new tab with properties {URL:p}
                        set current tab to r
                        set titleVal to item i of TLLines
                        set descVal to item i of DescLines
                        set updateCount to updateCount + 1
                        do shell script "echo The value: " & updateCount
                        delay 12
                        do JavaScript "document.getElementsByName('title')[0].value = '" & titleVal & "'; document.getElementsByName('description')[1].value = '" & descVal & "'; 
                                      document.getElementsByClassName('save-changes-button')[0].removeAttribute('disabled');
                                      document.getElementsByClassName('save-changes-button')[0].click();" in current tab
                        delay 4
                        close current tab
                        if updateCount is equal to 10 then
                            say "hi"
                            set updateCount to 0
                            delay 90
                        end if
                        if i = tot then exit repeat
                        repeat
                            delay 4
                            get URL of r
                        end repeat
                    end tell
                end tell
            end try
        end if
    end repeat
end run
几个月前,我在Safari上的YouTube上运行了这个脚本,没有任何问题。现在它不执行JavaScript操作。Safari的inspector中显示错误:

  • 内容安全策略指令“script src”的源列表包含无效源:“strict-dynamic”。将忽略该源。 postmessageRelay:0“
  • 拒绝执行脚本,因为其哈希、nonce或“不安全内联”未出现在内容安全策略的script src指令中
  • 如何绕过这些错误以使脚本能够运行?

    正如问题中的错误2所指出的那样,目前使策略在Safari中工作的修复方法是将其更改为指定相关脚本的哈希或nonce,或者添加
    'safe-inline'

    在支持
    'strict-dynamic'
    的浏览器中,
    'safe-inline'
    部分将被忽略

    这两个错误的原因都是Safari还不支持
    'strict-dynamic'
    。见下文:


    尽管如此,从问题中的当前信息来看,还不清楚现行CSP政策的具体内容。因此,除非您已经知道策略的位置,否则我想第一步是确定策略的指定位置,并在那里进行更改。

    我应该在哪里添加不安全的内联?如何将其作为JavaScript命令添加到此AppleScript中?我是在编辑一个元素来添加它,还是在文档的顶部?我只是重读了关于确定在哪里指定策略的最后一部分。这是YouTube视频的编辑页面,我无法链接,因为它需要帐户和登录。在搜索inspector时,我在这里找不到任何关于“nonce”、“unsafe inline”或“strict dynamic”的内容。我只是尝试在较旧版本的Safari(9)上运行我的AppleScript,它给了我更多的错误。两个月前我没有问题。如果有效的政策是由Youtube页面设置的,那么我想你无法将其更改为添加“不安全内联”或对其进行任何其他更改it@VagueExplanation很高兴听到你成功了