Include json file in webextension - google-chrome-extension

How to include json file (a dictionary) and then access data from it in my webextension? (Should work on Firefox/Chrome and preferrably others)

Another method is to load your JSON data as a variable in a regular javascript file:
json.js:
var data = {
1: "hello",
2: "world"
}
Then include it as you would include any other script.

Related

how to use jmeter JSR223 PreProcessor for reading each line from csv file

My requirement is to send (all the files bodies at once) the multiple JSON body to the API using POST method from JMeter.
I have a CSV file with all the file path in json_test_plan.csv file. And in each of the four files I have the JSON body. I used
In each line, I have mentioned a file path which contains the JSON body.
D:\jmeter_tests\plan1.json
D:\jmeter_tests\plan2.json
D:\jmeter_tests\plan3.json
D:\jmeter_tests\plan4.json
created a HTTP Request sampler with the Body data as mentioned below:
{__FileToString(${JSON},,)}
Added JSR223 PreProcessor as a child of the HTTP Request sampler which I use for sending the JSON input
Put the following code into Script area
new File("D:/jmeter_tests/json_test_plan.csv").readLines().each { line ->
def builder = new StringBuilder()
builder.append(new File(line).text).append(System.getProperty('line.separator'))
sampler.getArguments().removeAllArguments()
sampler.addNonEncodedArgument('', builder.toString(), '')
sampler.setPostBodyRaw(true)
}
Added a http header manager, added content-type and application/json as values for Name and Value field respectively
Added a CSV Dataset Config mentioning the CSV data source "D:/jmeter_tests/json_test_plan.csv"
Now the issue is, each time i run a jmeter test, the above just reads the last line(row) from CSV file "D:\jmeter_tests\plan4.json" and gives the required output. think there is some indexing issue in the code. Could someone pls help me to rea each row/line from the CSV and process.
thanks
It happens because you're calling sampler.getArguments().removeAllArguments() for each file. Just remove it and your code should start working more or less okayish.
You can also think about enhancing it to use Arguments class
def data = new org.apache.jmeter.config.Arguments()
def builder = new StringBuilder()
new File("D:/jmeter_tests/json_test_plan.csv").readLines().each { line ->
builder.append(new File(line).text).append(System.getProperty('line.separator'))
}
def body = new org.apache.jmeter.protocol.http.util.HTTPArgument('', builder.toString(), '', false)
body.setAlwaysEncoded(false)
data.addArgument(body)
sampler.setArguments(data)
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?

How supply default values in calling a remote endpoint

I am an amateur programmer and cannot figure this out based on the documentation and examples provided.
Based on their sample capsule on https://bixbydevelopers.com/dev/docs/sample-capsules/samples/http, they directly called
var response = http.getUrl(config.get('remote.url') + '/shoes', options);
They do have documentation on what http.getUrl parameters are but no examples on how it should be formatted syntax-wise.
I also don't know what would be the point of creating an endpoints.bxb for API calls file if they don't use it and just call it manually in the .js file.
Any help is greatly appreciated!
The base method signature for http.getUrl is http.getUrl(url, options) where the url variable is a String and the options variable is a JSON object containing any or all of the following keys:
format: Output format.
query: Object containing unencoded keys and values for URL query string.
cacheTime: Cache time in milliseconds.
basicAuth: Basic Authentication; value must be an object with username and password.
You can learn more by exploring the documentation's http section here.
Regarding the http sample you referenced: It shows multiple ways to reach the same outcome. The endpoints.bxb file has the two following action-endpoints:
A local endpoint where the GET is handled by the Javascript file:
action-endpoint (FindShoe) {
accepted-inputs ()
local-endpoint (FindShoe.js)
}
A remote endpoint where the GET is defined within the endopoints.bxb file itself and doesn't require a Javascript file.
action-endpoint (FindShoeRemoteEndpoint) {
accepted-inputs ()
remote-endpoint ("{remote.url}/shoes") {
method (GET)
}
}

X-Pages: fileUpload control preventing unwanted files from being uploaded

I am using the accept property in the fileUpload control to only allow certain file Types and prevent uploading .exe or other potentially harmful files.
application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/pdf,text/plain,image/gif,image/jpeg,image/pjpeg,image/png"
This works, however I am using a Tool called Burp Suite that allows me to intercept an acceptable file eg .txt that could contain harmful code and change the filename extension to .exe which is then upload to the X-Page database.
When I goto save the document and after Interception and changing to a .exe, I have added the following code to identify an exe file:
Can we manipulate what has been uploaded and change the file extension to a harmless .txt ?
var fileData:com.ibm.xsp.http.UploadedFile =facesContext.getExternalContext().getRequest().getParameterMap().get(getClientId('fileUpload1'));
if (fileData != null) {
var tempFile:java.io.File = fileData.getServerFile();
// Get the path
var filePath:String = tempFile.getParentFile().getAbsolutePath();
// Get file Name
var fileName:String = tempFile.getParentFile().getName();
// Get the Name of the file as it appeared on the client machine - the name on the server will NOT be the same
var clientFileName:String = fileData.getClientFileName();
}
var fileRight = clientFileName.slice(-4);
if (fileRight == ".exe")
{
//facesContext.getExternalContext().getRequest().getParameterMap().get(getClientId('fileUpload1').replace(".exe",".txt"))
//facesContext.getExternalContext().getRequest().getParameterMap().get(getClientId('fileUpload1').remove(".exe",0))
}
Yes, you can. You have on the properties of control two options 'Use original file name of uploaded file' and 'Replace file name of uploaded file...' where you can put name with extension 'name.txt' . I didn't try to change only extension... That is probably better in code to replace.

Jade loading a JSON file and assigning to variable

I have a JSON file in the same folder as the jade template.
Is there a way I can load the contents of the JSON file and assign it to a variable? (FYI - I am trying to do this outside of node.js passing render parameters, I am trying to get this accomplished within jade file itself)
I tried the code below and it does not work. Any pointers?
script.
var jsonValue = include ./demo_options.json
Within the jade, you can not load data, you can load in your node.js app;
var data = require('/path/to/your/demo_options.json');
//
res.render('page', {data: data});
And in your script you can use as follow:
.script
var jsonValue = #{ data }; //this part not sure if it will work

Chrome Extension: Local Storage, how to export

I have a chrome extension that saves a bunch of data to chrome.storage.local. I'm trying to find easy ways to export this data and package it into a file. I'm not constrained on what type of file it is (JSON, CSV, whatever), I just need to be able to export the contents into a standalone (and send-able) file. The extension is only run locally and the user would have access to all local files.
First, you need to get all data.
Then serialize the result.
Finally, offer it as a download to the user.
chrome.storage.local.get(null, function(items) { // null implies all items
// Convert object to a string.
var result = JSON.stringify(items);
// Save as file
var url = 'data:application/json;base64,' + btoa(result);
chrome.downloads.download({
url: url,
filename: 'filename_of_exported_file.json'
});
});
To use the chrome.downloads.download method, you need to declare the "downloads" permission in addition to the storage permission in the manifest file.
You should look here: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-extensions/AzO_taH2b7U
It shows exporting chrome local storage to JSON.
Hope it helps

Resources