loadContextGoodies is not defined - javascript

This is my pretty straight forward firefox plugin main.js. I run it and get 'loadContextGoodies is not defined', what is going wrong here?
const {Cc, Ci, Cu, Cr} = require("chrome");
var events = require("sdk/system/events");
var utils = require("sdk/window/utils");
var { MatchPattern } = require("sdk/util/match-pattern");
var pattern = new MatchPattern(/^https?:\/\/example\.com.*/);
function listener(event) {
var channel = event.subject.QueryInterface(Ci.nsIHttpChannel);
var url = event.subject.URI.spec;
if (isToBeRedirected(url)) {
channel.cancel(Cr.NS_BINDING_ABORTED);
var goodies = loadContextGoodies(channel);
var domWin = goodies.aDOMWindow;
var gBrowser = goodies.gBrowser;
var browser = goodies.browser;
var htmlWindow = goodies.contentWindow;
browser.loadURI("about:blank");
}
}
exports.main = function() {
events.on("http-on-modify-request", listener);
}
function isToBeRedirected(url) {
return pattern.test(url)
}
edit: I was totally overlooking the part of the source I used for the redirecting bit which contained the declaration of the function. I didnt notice it was a scrollbox.. Thanks for the answer though.

According to that answer : https://stackoverflow.com/a/22429478/1170900
You need to declare loadContextGoodies

Related

Nodejs require file depends on each other

Is it normal to have require for each other in both files? I have a requirement where AWS.js is managed in a separate file but AWS.js needs variable from index.js and index.js imports AWS.js.
As you see in the below example, I might have to include require for each other. Any solution to this?
index.js:
I can't move these variables to AWS.js because the event.Records[0].Sns.Message belongs to a function in index.js
var AWS = require('./AWS.js');
var sns = JSON.parse(event.Records[0].Sns.Message);
var sns_MetricName = sns.Trigger.MetricName;
var sns_NameSpace = sns.Trigger.Namespace;
AWS.js:
if(sns_NameSpace == "AWS/S3") {
keyFilter = ["BucketName", "StorageType"]
}
Workaround is to have both require each other. Any solution to this? Is this normal approach?
index.js:
var AWS = require('./AWS.js');
var sns = JSON.parse(event.Records[0].Sns.Message);
var sns_MetricName = sns.Trigger.MetricName;
var sns_NameSpace = sns.Trigger.Namespace;
exports.sns = sns;
exports.sns_MetricName = sns_MetricName;
exports.sns_NameSpace = sns_NameSpace;
AWS.js:
var index = require('./index.js');
if(index.sns_NameSpace == "AWS/S3") {
keyFilter = ["BucketName", "StorageType"]
}
Inject your dependencies. If AWS requires sns_NameSpace give it sns_NameSpace, don't import index:
AWS.js:
var keyFilter;
function init (sns_NameSpace) {
if(sns_NameSpace == "AWS/S3") {
keyFilter = ["BucketName", "StorageType"]
}
}
exports.init = init;
exports.keyFilter = keyFilter;
index.js:
var AWS = require('./AWS.js');
var sns = JSON.parse(event.Records[0].Sns.Message);
var sns_MetricName = sns.Trigger.MetricName;
var sns_NameSpace = sns.Trigger.Namespace;
AWS.init(sns_NameSpace); // <------- Pass the value HERE!!
console.log(AWS.keyFilter); // <---- Prints ["BucketName","StorageType"]
exports.sns = sns;
exports.sns_MetricName = sns_MetricName;
exports.sns_NameSpace = sns_NameSpace;

nativescript: modal property is undefined

I'm create datepicker modal select library on nativescript.
var pagesModule = require("ui/page");
var datePickerModule = require("ui/date-picker");
var moment = require('momentjs');
var frame = require('ui/frame');
module.exports.init = function(tarih, callBack) {
var dt = new datePickerModule.DatePicker();
var page = new pagesModule.Page();
page.content = dt;
page.height = 250;
var parent = frame.topmost().currentPage;
parent.modal.showModal(page, '', function() {
callBack();
});
};
I'm calling this library on main js file;
var dm = require('../../../lib/dateModal');
exports.tarihCagir = function(nesne) {
dm.init('', function() {
console.log('kapatıldı');
});
};
I'm getting this error; 'TypeError: Cannot read property 'showModal' of undefined.
This problem may be not complicated but i'm newbie for nativescript.
I'm solved problem. Changed parent.modal.showModal code to parent.showModal.

Why is this an unreachable code?

I'm calling the function getKeywords from another function and got an Unrecheable code detected section and don't understand why. Any help?
var env = require('dotenv').config();
var request = require('request')
var getKeywords = function(){
request.get('URI', //URI IS CORRECT IN MY CODE
function(err, httpResponse, body){
if(err){ //UNREACHABLE CODE DETECTED
console.error("request.post Error:", err);
return false;
} //UNREACHABLE CODE DETECTED
else{
console.log('Im here');
return JSON.parse(httpResponse.body).keywords;
}
});
}
module.export = getKeywords;
Here is the calling code.
var getKeywords = require('./getKeywords.js');
var keywords = new getKeywords();
var env = require('dotenv').config();
var difflib = require('difflib');
var postMention = require('./postMention.js');
var detection = function(obj, i){
var keyword = keywords[i];
var mentionObject = {
//some json
//postMention(mentionObject);
}
}
module.exports = detection;
Some tools have the ability to analyze every call to your function. It may be possible that all the places in your code that call the function you never set err parameter to true.

JScript to Javascript Conversion

The code below is a web service call to ICEPortal which is in JScript.NET format. Currently Iceportal doesn't have a webservice call using javascript. Has anybody done this using javascript? I need your help to convert the code below to javascript format.
// JScript.NET
var h:ICEPortal.ICEWebService = new ICEPortal.ICEWebService();
var myHeader:ICEPortal.ICEAuthHeader = new ICEPortal.ICEAuthHeader();
myHeader.Username = "distrib#distrib.com";
myHeader.Password = "password";
h.ICEAuthHeaderValue = myHeader;
var brochure:ICEPortal.Brochure;
var ErrorMsg;
var result = h.GetBrochure("MyMappedID", ErrorMsg, brochure);
I think you just need to remove the type definitions (in bold below):
var myHeader :ICEPortal.ICEAuthHeader = new ICEPortal.ICEAuthHeader();)
No idea what the ICEPortal classes are, but if they are available to your Javascript in the global namespace, the following should work. I've added these stubs in for the ICEPortal to test and it works fine for me in Chrome.
You'll obviously want to remove the stubs.
// stubbing out ICEPortal(s)
ICEPortal = {};
ICEPortal.ICEWebService = function() { return true; };
ICEPortal.ICEAuthHeader = function() { return true; };
ICEPortal.ICEWebService.prototype.GetBrochure = function() { return true; };
// end stubbing ICEPortal(s)
var h = new ICEPortal.ICEWebService();
var myHeader = new ICEPortal.ICEAuthHeader();
myHeader.Username = "distrib#distrib.com";
myHeader.Password = "password";
h.ICEAuthHeaderValue = myHeader;
var brochure;
var ErrorMsg;
var result = h.GetBrochure("MyMappedID", ErrorMsg, brochure);

.setText() not working

I have a function which by design should:
Create new directory
Copy docs from specified dir to newly created one
Set text to that copied docs
And I implemented it in such way:
function copyDocsAndSetText(fromDirId, toDirId) {
var toDir = DriveApp.openFolderById(toDirId);
var cwd = toDir.createFolder("New folder");
var fromDir = DriveApp.openFolderById(fromDirId);
var originalFiles = fromDir.getFiles();
while (originalFiles.hasNext()) {
var file = originalFiles.next();
file.makeCopy(cwd);
}
var copiedFiles = cwd.getFiles();
while (copiedFiles.hasNext()) {
var file = copiedFiles.next();
var doc = DocumentApp.openById(file.getId());
doc.getBody().setText("It works!");
}
}
I should see "It works!" as a content of each file inside newly created directory but I don't. What I'm doing wrong? Or it is some kind of bug?
You have done a small mistake, replace openFolderById with getFolderById
var toDir = DriveApp.getFolderById(toDirId);
var fromDir = DriveApp.getFolderById(fromDirId);

Categories

Resources