WebExtension: Block request after response header received in Firefox and Chrome Extension

Well. Firefox finally admitted that Chrome’s extension system is better than it’s XUL or Add-on SDK.

So from Firefox 45+, it started to support WebExtension. And now, it even does not allow any extension that is not built with WebExtension API.

This is a good news, because if you want your extension run on both Chrome and Firefox. you won’t need to build twice.

However, even Firefox is trying to support all of the WebExtension API. There are still some differences between Chrome and Firefox.

Recently I got this one.

I was trying to block some requests with the WebRequest API after response header just received. In Chrome, you can easily do it with an onHeadersReceived listener. like this:

 chrome.webRequest.onHeadersReceived.addListener(
    function (details) {
        let block = THE CONDITIONS THAT YOU WANT TO USE;
        return {cancel: block};

    },
    {urls: ["URL PATTERN"], types: ["TYPES"]},
    ["blocking"]); 

But in Firefox, this is not gonna work. Because in Firefox, you can not block a request after the response headers received, you can only redirect it. So you need to to this:

 chrome.webRequest.onHeadersReceived.addListener(
    function (details) {
        let block = THE CONDITIONS THAT YOU WANT TO USE;
        return {cancel: block, redirectUrl: "://127.0.0.1"};

    },
    {urls: ["URL PATTERN"], types: ["TYPES"]},
    ["blocking"]); 

with the redirectUrl: “://127.0.0.1”, you will redirect it to a local address, and means block it.

How to fix “[Error] ScriptError: Document DocumetID is missing (perhaps it was deleted?)” in Google Script

I’ve created a Google Script APP to help someone export Gmail data to Google SpreadSheet.

It works well when I was testing. But after I publish it as web app, and other users got an error which says

[Error] ScriptError: Document DOCUMENT_ID is missing (perhaps it was deleted?).

And no authorize permission form popups up.  I did not get any useful answer in Google.

After several tests I found I made a stupid mistake.

When publishing the Google Script as web app or other types of APP. There are several options need to take carefully.

Execute the app as:

should set as “User accessing the web app“. (The default value is  Me(myself email)).

With this option, when user first use your app, the authorize permission form will popup and ask user to allow your app access their Google APP.

And no more Document is missing error.

Also don’t forget to chose Anyone in the Who has access to the app option.

 

 

 

How to debug Chrome extension Native Messaging app

 

Here is how to debug native messageing: enable logging.

By adding a flag, it can open Chrome logging window when starting Chrome.

For Windows, you just need to right click on the Chrome icon in your installation folder / shortcut / taskbar —— Properties  —— add this line behind the target string:

[code]–enable-logging –v=1[/code]

A logging window will start with the Chrome. There the native messaging stuff will be print out.

迄今为止最便捷的免费SSL证书服务:腾讯云

现在都用SSL了。 这段时间一直在折腾启用这个网站的SSL,前后试过Let’s encrypt 和StartSSL两个服务,均出现各种问题,配置过程也比较繁琐。耗费掉数十个小时不说,也有些备受打击。

而且StartSSL据称被著名流氓公司奇虎360收购了。对于Let’s encrypt,Chrome和iOS似乎对个人签署的证书也不友好,经常显示不信任。

辗转搜索,有人推荐用腾讯云提供的免费个人证书服务,试用下来步骤非常简单,配置也相当傻瓜化,几分钟即可完成。

这里粗略记录一下。

腾讯云SSL服务地址是:https://console.qcloud.com/ssl

若你还未注册,则需要用QQ或者微信登录,然后通过手机号进行简单的注册。

要申请证书,还需要使用真实姓名和身份证号进行实名认证。填入后若正确可即时通过认证,无需上传照片。

然后点击申请证书, 选择左侧的免费证书即可(也可在右侧购买收费证书) Read More

This Site Enabled SSL

Today I finally got some time to work on my own site.

This small blog used to on a small VPS.

I moved it to Vultr because I heard it is a powerful VPS and it’s price is fair too.

I also enabled SSL, using Free SSL certificate supplier Tencent Cloud service. It’s good, easy to config and doesn’t need to verify again in 1 years.

Got A+ 🙂

iPhone 6S 自动关机问题可能比苹果想象的要严重

在中消协发出查询函以后,苹果对iPhone 6S 近期大量出现的自动关机问题给出的回复是, 电池相关的某个部件在组装前由于长时间暴露在受控环境空气中的时间过长。导致装有这批电池的6S会出现在较寒冷温度下自动关机的问题。

苹果定义的是“一小批”在2015年9月和10月出产的手机会有这样的问题, 并提供了查询网页让消费者查询自己的手机是否在这“一小批”中。符合此条件的手机将可以免费更换电池,若此前已经付费更换电池的用户,则可以报销费用。

我本人的6S也不幸中招,然而并非苹果说的较寒冷的温度下。根据我的使用记录,在室温14度左右下,依然出现电量高达40%以上的时候关机,室温6度左右的时候,出现电量迅速消耗的情况,大约每一分钟掉2%左右的电量,而我仅仅是在浏览文字网页。

而根据我加的几个相关QQ群内的反应,很多并非2015年9月、10月生产的iPhone也有相应的问题,型号从5到6 PLUS都有。而在其他社交媒体上抱怨自己手机这一问题的也很多,遍布全球。因此有理由相信,这并非苹果说的一小批。

其实去年我的一部5C也出现一样的情况,好在当时在保,苹果给换机了事。可惜后来不就这部5C就丢了。

虽然之前给出了免费更换电池的解决措施,然而很多用户反应,即使在更换新电池以后,依然会出现自动关机现象,有些人在更换电池以后这一问题虽然得以缓解,但并未完全解决。不少用户猜测问题可能出在主板上。出于此原因,我一直未去更换自己电池。

苹果说本周推出的iOS10系统更新将包含可以更有效诊断这一问题的内容,期待苹果能给出一个满意的解答。

 

KickAssTorrent is down… for a stupid mistake

The world’s biggest torrent sharing website KickAssTorrent was shutdown at 22/7/2016.

This is what happens:

  • An undercover agent of FBI contacted the owner of kickass for advertisement, got his email ID
  • The Owner then purchased something with same email ID in Apple’s store
  • Got exposed. The police arrested him in Poland
  • KickAssTorrent website was shutdown

He hided so many years for running this website, how comes he use the same email to purchase in Apple store and contact with others?

So stupid.

Firefox: How to install and use addon that is not from AMO

In former version, users can install Firefox addon easily by drag and drop the addon file (.xpi file)  into Firefox to install and use it.

But now, user can not do this by default. User can only install addon from AMO (https://addon.mozilla.org). If you download an addon from other website or like me develop addon self. when you drag and drop the file into Firefox. it will be disabled and can not be enable. It says : ADDON NAME could not be verified for use in Firefox and has been disabled.  like this(I’m using Nightly Firefox):

Unnamed QQ Screenshot20151104000045

well, it’s easy to pass this by these steps.

1: Navigate to about:config in Firefox (input about:config into Firefox’s address bar and hit Enter)

2: You might see a warning screen warning the action is not safe. Just hit the blue button  I’ll be careful, I promise .

3:You will see a long list. Input the keywords xpinstall  in the search bar.

4: Find the xpinstall.signatures.required, it’s value should be true now. click this line, change the value to false.

xpinstall

5: You are done, you will see that your addon enabled and working:)