Safari扩展safari.application错误 [英] Safari Extension safari.application error

查看:65
本文介绍了Safari扩展safari.application错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对safari进行扩展,我使用命令= showNote

I'm making an extension for safari I created a context item with command = showNote

在调试器中,我在第8行(最后一行)出现以下错误TypeError: Result of expression 'safari.application' [undefined] is not an object

In debugger I get the follwing error TypeError: Result of expression 'safari.application' [undefined] is not an object on line 8(the last line)

在此之前您需要包含或调用任何东西吗?

are there any things you need to include or call before this works?

main.js

function showNote(event){
    if(event.command == "showNote"){
        addElement = document.createElement('<div id="safExtNote"><textarea id="safExtNoteText"></textarea><button id="safExtSave">Save</safExtNote></div>');
        document.body.appendChild(addElement)
        alert("im online");
    }
}
safari.application.addEventListener("command", showNote, false);

推荐答案

我自己尝试创建工具栏命令时就遇到了这个问题.原来我把JS放错了地方.我将其作为开始脚本添加到注入的扩展内容"中.需要创建一个包含JS的HTML页面并将其设置为全局页面文件".

Just ran into this problem myself trying to create a toolbar command. Turns out I was putting the JS in the wrong place. I added it to the "Injected Extension Content" as a start script. Needed to create an HTML page that included the JS and set that as the Global Page File.

切换一下,您应该已设置好,假设这是我刚遇到的相同问题.

Switch that around and you should be set, assuming it's the same problem I just ran into.

这篇关于Safari扩展safari.application错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆