Firefox SDK block content-type - firefox-addon-sdk

I am developing an add-on for Firefox and i want to block a special kind of requests in content-type.
For example i want to block the application/x-rar content-types and show a message in console.log

You are able to intercept the requests by observing the http-on-examine-response notification event and check getResponseHeader('Content-Type') for application/x-rar.
'use strict';
const {
Ci, Cr
} = require('chrome');
const events = require('sdk/system/events');
events.on('http-on-examine-response', function(event) {
let channel = event.subject.QueryInterface(Ci.nsIHttpChannel);
let contentType = channel.getResponseHeader('Content-Type');
if(contentType === 'applicaiton/x-rar'){
event.subject.cancel(Cr.NS_BINDING_ABORTED);
console.log('Aborted Request', channel.name);
}
});
Best of luck with developing your add-on.

Related

Intercepting fetch request on Flutter webview_flutter package

How can i intercept (listening) fetch request on webview_flutter package? Is it posible?
Nowadays, i was inspected flutter_inappwebview plugin. But this plugin is deprecated. Last commit on GitHub is 12 months ago.
Therefore i want intercept fetch request on webview_flutter, official Flutter package.
Is it posible making this flutter way or javascript way?
SOLVED # 👍
I have found a solve.
I have created two interceptor on js side
1. Fetch API Interceptor
//FETCH INTERCEPTOR
const { fetch: originalFetch } = window;
window.fetch = async (...args) => {
let [resource, config] = args;
var requestedURL = resource.valueOf();
console.log("requested url: "+requestedURL)
if (requestedURL=="https://my-json-server.typicode.com/typicode/demo/comments"){
var resp = new Response().statusText="Status not sent";
document.querySelector('.status').style.backgroundColor="red";
return resp;
}else{
const response = await originalFetch(resource, config);
document.querySelector('.status').style.backgroundColor="green";
return response;
}
};
Basically replacing original window fetch api to our created fake fetch api. It's called Monkey Patching.
2. XMLHttpRequest Interceptor
//XHR INTERCEPTOR
((() => {
const origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function() {
console.log('request started!');
this.addEventListener('load', function() {
console.log(this.responseURL);
});
// origOpen.apply(this, arguments);
};
}))();
and we can inject these js codes to webpage opened by Webview. with:
https://pub.dev/documentation/webview_flutter/latest/webview_flutter/WebViewController/runJavascript.html

Using audio files as no input prompts in Google Actions

I am trying to set up re-prompts in my Google Action, and I require them to be audio files.
This is my implementation:
'use strict';
const { dialogflow } = require("actions-on-google");
const functions = require("firebase-functions");
const app = dialogflow();
app.intent('Default Welcome Intent', (conv) => {
conv.noInputs = [`<speak> <audio src = "https://myurl.com/audio/myfile.mp3">My audio file</audio></speak>`];
console.log("Logging the conversation object... ");
console.log(JSON.stringify(conv));
conv.ask("Hello! ");
});
exports.yourAction = functions.https.onRequest(app);
However, at the moment it will just read the raw string of this noInputs array when I do a "no input" in the dev console!
Using this kind of static no-input handling is not suggested.
Better is to create an Intent that handles the actions_intent_NO_INPUT Event. You can then use the response section (or a response from your Fulfillment) to include SSML with the audio tag.

Ionic Worklight Page not displaying after HTTP request

I'm having an issue displaying the content in the page after the Worklight http request has been executed.
The weird thing is that when I go to another page and I come back, the content gets displayed. It's like if it needs to be refreshed or something. I can see the console.log() data was received, but page was not refreshed.
This is my code:
$stateProvider.state('accounts', {
url: "/accounts",
templateUrl: 'views/accounts.html',
controller: function($scope, $ionicScrollDelegate, $rootScope){
var req = new WLResourceRequest("/adapters/JavaMQ/bankmq/getAccounts/"+$rootScope.globalReqUserId, WLResourceRequest.GET);
req.send().then(function(resp){
var x2js = new X2JS();
resp.responseText = x2js.xml_str2json(resp.responseText); //to JSON
$scope.reqUserId = resp.responseText['ASI_Message']['Riyad_Bank_Header']['Requestor_User_ID'];
$scope.accountsList = resp.responseText['ASI_Message']['Repeating_Group_Section']['Repeating_Group'];
console.log($rootScope);
})
}
});
UPDATE:
I noticed that I also keep getting the following when I moved the project to Windows (Never happened in my mac)
Deviceready has not fired after 5 seconds
Channel not fired: onCordovaInfoReady
Channel not fired: onCordovaConnectionReady
I don't really know Worklight but the documentation indicate that the send().then() handles both the onSuccess and onFailure.
Maybe the then() is expecting 2 parameters like this:
var request = WLResourceRequest(url, method, timeout);
request.send(content).then(
function(response) {
// success flow
},
function(error) {
// fail flow
}
);
If that doesn't work, can you put a breakpoint at the start of var x2js = new X2JS(); and tell us what happens?

How to use POST method in Appcelerator Titanium for iPhone?

I have used the POST method in Titanium for Android app and it is working fine. But in iPhoen Simulator it shows a blank array in the server side to be posted.
var req = Titanium.Network.createHTTPClient({
timeout : 15000
});
req.open("POST", url);
req.onload = function(e) {
//YOUR CODE HERE
}
req.onerror = function(e) {
//YOUR CODE HERE
}
req.send(params);
If, server requires json format of data than you can use req.send(JSON.stringify(params)) otherwise you can send it simply.

Titanium xhr events not firing

I have been trying to get a simple xhr request to work but for some unknown reasons nothing happens, not even the onerror function fires off.
var xhr = Ti.Network.createHTTPClient();
xhr.onload = function() {
Titanium.API.log('Success');
}
xhr.onerror = function() {
Titanium.API.log('Error');
}
xhr.open("GET","http://www.google.com/");
xhr.send();
I have tried this with a new created project and still no luck. Using little snitch I noticed that a connection is made by the app to the given url ... but still nothing fires off.
What am I missing?
Also I'm developing on an iPhone Simulator.
I don't think there's anything wrong with the XHR request - the Titanium.API.log function takes two arguments, but you're only giving it one, so it's probably just not printing to the console. The Titanium documentation is down at the moment so I can't link you to the correct API, but if you change your code to use Ti.API.info, for example, you should see something printed. This works for me:
var xhr = Ti.Network.createHTTPClient();
xhr.onload = function() {
Titanium.API.info('Success');
}
xhr.onerror = function() {
Titanium.API.info('Error');
}
xhr.open("GET","http://www.google.com/");
xhr.send();