通过Chrome上的KBX扩展名安装时,Kynetx应用无法正常工作 [英] Kynetx app not working when installed via KBX extension on Chrome

查看:100
本文介绍了通过Chrome上的KBX扩展名安装时,Kynetx应用无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用正在使用 jQuery.getScript()加载外部javascript文件.当我使用小书签或扩展程序启动应用程序时,一切正常.当通过KBX通过 Chrome 在具有 KBX扩展名的内部通过KBX安装应用程序时,JavaScript文件中包含的函数不再可在回调中访问,并且我得到:未被捕获ReferenceError:未定义myfunc .

My app is loading an external javascript file with jQuery.getScript(). When I use the bookmarklet or an extension to start the app everything works fine. When the app is installed through KBX though inside Chrome with the KBX extension the included functions inside the javascript file are not accessible in the callback anymore and I get : Uncaught ReferenceError: myfunc is not defined .

是否有任何技巧可以访问包含的功能?

书签:javascript:(function(){var d=document;var s=d.createElement('script');s.text="KOBJ_config={'rids':['a1135x30']};";d.body.appendChild(s);var l=d.createElement('script');l.src='http://init.kobj.net/js/shared/kobj-static.js';d.body.appendChild(l);})()

Chrome扩展程序: crx

Chrome extension : crx

通过KBX安装的网址:应用在KBX上

url for installation via KBX : app on KBX

以下是规则集:

ruleset a1135x30 {
  meta {
    name "test_external_js_loading"
    description <<
debugging external loading in kbx
    >>
    author "loic devaux"
    logging on
  }

  dispatch {
    domain ".*"

  }

  global {

  }

  rule first_rule {
    select when pageview ".*" setting ()
    // pre {   }
    // notify("Hello World", "This is a sample rule.");
    {
        emit <|

        $K.getScript('http\:\/\/lolo.asia/kynetx_debug/js/myfunc.js',function() {
                myfunc();
                /*
                * myfunc.js content:
                myfunc = function(){
                console.log('running myfunc');
                };
                */
            }
        );

        |>
    }  
  }
}

推荐答案

我不确定您的问题是否与KBX在其中运行代码的沙盒环境有关,但我认为可能与之有关.这是我写的有关处理KBX沙盒环境的帖子 http://geek.michaelgrace.org/2011/03/kynetxs-new-sandboxed-browser-extensions/

I'm not completely sure that your issue has to do with the sandboxed environment that the KBX runs your code in but I think it might. Here is a post I wrote about dealing with the sandboxed environment of the KBX http://geek.michaelgrace.org/2011/03/kynetxs-new-sandboxed-browser-extensions/

我最近在以下位置发布了"Old School Retweet" Kynetx应用 Kynetx应用商店以获取新发布的浏览器扩展.我非常喜欢这些新扩展以及它们对用户和开发人员所做的所有工作.当我在应用商店中发布该应用时,我忘记了的一点是,新扩展名已被沙箱化. 因为扩展是沙盒,所以扩展中的所有脚本的运行都与以前的Kynetx扩展中的脚本有所不同.无需过多讨论技术细节,以前的扩展只是将JavaScript注入了页面,而新的扩展则在可访问DOM但无法访问页面上其他任何内容的沙箱中运行JavaScript.由于此更改,自从我使用Twitter.com加载的jQuery来调出新的tweet框以来,我的转推应用程序中断了(之所以这样做,是因为Twitter.com使用该库绑定了click事件并触发该事件,它必须来自绑定它的同一个库).值得庆幸的是,在朋友的帮助下,我能够在Firefox和Chrome的沙盒环境中得到解决. 我是怎么做到的... 如果该应用程序不在沙盒中运行,那么我可以访问Twitter.com加载的jQuery,以打开一个新的推文框

I recently released my "Old School Retweet" Kynetx app in the Kynetx app store for the newly released browser extensions. I super love the new extensions and all that they do for users and developers alike. Something that I forgot when I released the app in the app store is that the new extension are sandboxed. Because the extensions are sandboxed, all of the scripts from the extensions run a bit differently than they used to in the previous Kynetx extensions. Without getting into the technical details too much, the previous extensions just injected JavaScript into the page and the new extensions run JavaScript in a sandbox which has access to the DOM but can’t access anything else on the page. Because of this change my retweet app broke since I was using the jQuery loaded by Twitter.com to bring up the new tweet box (I do this because Twitter.com used that library to bind a click event and to trigger that event it has to be from the same library that bound it). Thankfully, with the help of a friend, I was able to get a work around for both Firefox and Chrome’s sandbox environment. How I did it… If the app is run not inside a sandbox I can just access the jQuery that Twitter.com loads to open a new tweet box

$("#new-tweet").trigger("click");

在Firefox沙箱中,我可以访问沙箱外部的页面

From within the Firefox sandbox I can access the page outside of the sandbox

window['$']("#new-tweet").trigger("click");

如果我在Chrome沙箱中,则可以创建一个脚本元素,其中包含要执行的JavaScript.粗暴的,但是行得通. :)

If I am in the Chrome sandbox I can create a script element that has the JavaScript that I want to execute. Crude, but it works. : )

var trigger_click_script = document.createElement("script");
var fallback = "window['$']('#new-tweet').trigger('click');";
trigger_click_script.innerHTML = fallback;
document.getElementsByTagName("head")[0].appendChild(trigger_click_script);

这是我最后得到的JavaScript代码,当用户单击转推"按钮时,该代码就会执行.

Here is the JavaScript code that I ended up with that gets executed when a user clicks on the retweet button.

// get stuff to retweet
var tweet = $K(this).parents(".tweet-content").find(".tweet-text").text();
var name = $K(this).parents(".tweet-content").find(".tweet-screen-name").text();

// build tweet
var retweet = "RT @"+name+" "+tweet;

// open new tweet box
$("#new-tweet").trigger("click");

// hack for FF sandbox
if ($("#tweet-dialog:visible").length === 0) {
  window['$']("#new-tweet").trigger("click");
}

// put tweet in new tweet box
$K(".draggable textarea.twitter-anywhere-tweet-box-editor").val(retweet).focus();
$K("#tweet_dialog a.tweet-button.button.disabled").removeClass("disabled");

// hack for chrome sandbox
if ($("#tweet-dialog:visible").length === 0) {
  var fallback = "window['$']('#new-tweet').trigger('click'); ";
  fallback += "window['$']('.draggable textarea.twitter-anywhere-tweet-box-editor').val('"+retweet+"').focus(); ";
  fallback += "window['$']('#tweet_dialog a.tweet-button.button.disabled').removeClass('disabled'); ";
  var trigger_click_script = document.createElement("script");
  trigger_click_script.innerHTML = fallback;
  document.getElementsByTagName("head")[0].appendChild(trigger_click_script);
}

这篇关于通过Chrome上的KBX扩展名安装时,Kynetx应用无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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