Adding HTTP Header to Chrome OS APP is not working - google-chrome-extension

I want to add header AppVersion to my chrome os app
here what I did
chrome.webRequest.onHeadersReceived.addListener(
function(details) {
const newHeader = {name:"appVersion", value:"chrome|2.1"};
const responseHeaders = details.responseHeaders.concat(newHeader);
return { responseHeaders };
},
// filters
{
urls: ["https://website.link/*"],
},
// extraInfoSpec
["blocking","responseHeaders", "extraHeaders"]
);
but it is not working

Related

How to add utm tags to a wix form?

I am currently attempting to include UTM tags in a webhook that I am sending from a wix form. However, upon sending the webhook, I am either receiving an empty response or receiving "google.co.il" source. I am expecting specifically Google Ads or email sources.
I have added the code that I am using in an attempt to make this function properly. Any assistance or guidance would be greatly appreciated..
export function wixForms1_wixFormSubmitted(event) {
var obj = {};
var i = 0;
for (i=0;i<event.fields.length;i++){
obj[event.fields[i].id] = event.fields[i].fieldValue;
}
//console.log(obj);
fetch( "https://hook.eu1.make.com/62tsltjotop6iwboufggguuxhhqrjaen", {
"method": "post",
"headers": {
"Content-Type": "application/json"
},
"body": JSON.stringify(obj)
} )
.then( (httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
} else {
return Promise.reject("Fetch did not succeed");
}
} )
.then( (json) => console.log(json) )
.catch(err => console.log(err));
}
$w.onReady(function () {
const query = wixLocation.query;
if (query) {
$w('#refbox').value = JSON.stringify(query);
}
let params = wixLocation.query
console.log(params)
$w('#campaign').value = params.campaign_name
$w('#source').value = params.utm_source
});
import wixWindow from 'wix-window';
import wixLocation from 'wix-location';
});
import wixWindow from 'wix-window';
import wixLocation from 'wix-location';
import {local, session, memory} from 'wix-storage';
let referrer = wixWindow.referrer;
let previousPageURL;
$w.onReady(function () {
previousPageURL = session.getItem("page");
session.setItem("page", wixLocation.url);
});
$w.onReady(function () {
// Write your JavaScript here
const prvurl = wixLocation.url;
if (prvurl) {
$w('#prvurl').value = JSON.stringify(prvurl);
}
// To select an element by ID use: $w("#elementID")
// Click "Preview" to run your code
const query = wixWindow.referrer;
if (query) {
$w('#refbox').value = JSON.stringify(query);
}
}
);

How To detect a specific Extension that communicate with my webpage

In my webpage i want to make a script to detect a specific extension that manipulate my code
I've already tried the following in my webpage
async function tst(){
debugger;
window.addEventListener("PassToBackground", function(evt) {
var blockedExID="bjnkkhimoaclnddigpphpgkfgeggokam";
if (!chrome.runtime) {
// Chrome 20-21
chrome.runtime = chrome.extension;
} else if(!chrome.runtime.onMessage) {
// Chrome 22-25
chrome.runtime.onMessage = chrome.extension.onMessage;
chrome.runtime.sendMessage = chrome.extension.sendMessage;
chrome.runtime.onConnect = chrome.extension.onConnect;
chrome.runtime.connect = chrome.extension.connect;
}
var runtimeOrExtension = chrome.runtime && chrome.runtime.sendMessage ?
'runtime' : 'extension';
var reponse= chrome[runtimeOrExtension].sendMessage(blockedExID,{ message: "version" },{
function (reply) {
if (reply) {
alert(reply);
}
}
});
chrome[runtimeOrExtension].sendMessage({greeting: 'hello'});
}, false);
}
but chrome.runtime is undefiled

How to send requests using custom cookies with Request-promise

I am working on a print app and I need to get some data from a protected resources.
the only way I can be signed in is using a browser so I am using phantom as browser.
I manged to sign in and get the cookies but I don't know how to use the cookies with request-promise to send the requests with the cookies I got when I signed in.
Here is my simplified code:
import * as phantom from "phantom";
import * as requestPromise from "request-promise-native";
requestPromise.defaults({ rejectUnauthorized: false });
(async function () {
const instance = await phantom.create([
"--ignore-ssl-errors=true",
"--cookies-file=cookies.txt",
"--web-security=false",
"--ssl-protocol=any"
]);
const page = await instance.createPage();
const status = await page.open("http://localhost:3000/auth/login-html");
console.log("status", status);
let result = await page.evaluate(() => {
(document.getElementById("username") as HTMLInputElement).value = "test#email.com";
(document.getElementById("password") as HTMLInputElement).value="password";
(document.getElementById("login") as HTMLElement).click();
return true;
});
// Get the cookies
let cookies = await page.property("cookies");
console.log(cookies)
/** [{ domain: 'my-app-resource-domain.com',
httponly: true,
name: 'ticket',
path: '/',
secure: false,
value: '6823a-78c0a4ee82c0' },
{ domain: 'my-app-resource-domain.com',
httponly: true,
name: 'JSESSIONID',
path: '/',
secure: false,
value: '9CB8396A05ABA178' }] **/
let cookiesSring = getStringCookies(cookies) // "ticket=6823a-78c0a4ee82c0&JSESSIONID=9CB8396A05ABA178"
requestPromise.cookie(cookiesSring );
// Send request to get data from protected resource
let res = await requestPromise.get("http://my-app-resource-domain.com/api/get-charts")
})();
The documentation is very unclear about it, but the cookie function actually only just parses and returns a cookie string as an object. It does not set the cookie to be sent in the request.
You have two options. Either you use tough-cookie to create a cookie jar and include it in the options, as shown in the official documentation, or you simply include your cookies in the header directly.
Using a cookie jar
import * as requestPromise from "request-promise-native";
import { Cookie } from "tough-cookie";
// ...
const pageCookies = await page.property("cookies");
// rename the "httponly" property to "httpOnly" since that's what
// tough-cookie expects
const cookies = pageCookies.map(pageCookie => {
const cookie = { ...pageCookie };
cookie.httpOnly = pageCookie.httponly;
delete cookie.httpOnly;
return new Cookie(cookie);
});
const cookieJar = requestPromise.jar();
// Set the cookies to apply only to my-app-resource-domain.com
cookies.forEach(cookie =>
cookieJar.setCookie(cookie, "http://my-app-resource-domain.com/")
);
const options = {
uri: "http://my-app-resource-domain.com/api/get-charts",
jar: cookieJar
};
const res = await requestPromise.get(options);
Using headers
import * as requestPromise from "request-promise-native";
import * as querystring from "querystring";
// ...
const pageCookies = await page.property("cookies");
// pluck the name and value from the page cookies into
// key-value pairs in an object
const cookieObjects = pageCookies.reduce((acc, cookie) => {
acc[cookie.name] = cookie.value;
return acc;
}, {});
// stringify the cookies to the familiar "cookie=value; cookie2=value" format
const cookieString = querystring.stringify(cookieObjects, "; ");
const options = {
uri: "http://my-app-resource-domain.com/api/get-charts",
headers: {
Cookie: `${cookieString};`
}
};
const res = await requestPromise.get(options);

npm react-native-fetch-blob - "RNFetchBlob.fetch is not a function"

I am using the npm package react-native-fetch-blob.
I have followed all the steps from the git repository to use the package.
I then imported the package using the following line:
var RNFetchBlob = require('react-native-fetch-blob');
I am trying to request a BLOB containing an image from the a server.
This is my main method.
fetchAttachment: function(attachment_uri) {
var authToken = 'youWillNeverGetThis!'
var deviceId = '123';
var xAuthToken = deviceId+'#'+authToken
//Authorization : 'Bearer access-token...',
// send http request in a new thread (using native code)
RNFetchBlob.fetch('GET', config.apiRoot+'/app/'+attachment_uri, {
'Origin': 'http://10.0.1.23:8081',
'X-AuthToken': xAuthToken
})
// when response status code is 200
.then((res) => {
// the conversion is done in native code
let base64Str = res.base64()
// the following conversions are done in js, it's SYNC
let text = res.text()
let json = res.json()
})
// Status code is not 200
.catch((errorMessage, statusCode) => {
// error handling
});
}
I keep receiving the following error:
"Possible Unhandled Promise Refection(id: 0): TypeError: RNFetchBlob.fetch is not a function".
Any ideas?
The issue is you are using ES5 style require statements with a library written against ES6/ES2015. You have two options:
ES5:
var RNFetchBlob = require('react-native-fetch-blob').default
ES6:
import RNFetchBlob from 'react-native-fetch-blob'
My import looks like this : import RNFetchBlob from 'rn-fetch-blob';
but I'v got an error : TypeError: RNFetchBlob.scanFile is not a function
My code:
const downloadAudio = async () => {
const { config, fs } = RNFetchBlob;
const meditationFilesPath =
Platform.OS == 'android'
? `${fs.dirs.DownloadDir}/meditations/${id}`
: `${fs.dirs.DocumentDir}/meditations/${id}`;
let audio_URL = track;
let options = {
fileCache: true,
path: meditationFilesPath + `/${id}.mp3`,
addAndroidDownloads: {
// Related to the Android only
useDownloadManager: true,
notification: true,
path: meditationFilesPath + `/${id}.mp3`,
description: 'Audio',
},
};
try {
const resAudio = await config(options).fetch('GET', audio_URL.uri);
if (resAudio) {
const audio = await RNFetchBlob.fs.scanFile([
{ path: resAudio.path(), mime: 'audio/mpeg' },
]);
console.log('res -> ', audio);
Alert.alert('Audio Downloaded Successfully.');
}
} catch (error) {
console.error('error from downloadAudio', error);
}
};

http header spoofer in chrome

I am trying to develop a chrome tool to spoof HTTP request and response headers. Request spoofing works fine. This code changes UA in request header but in response header I can't change anything. e.g. I am trying to change "Set-Cookie" but it won't work. I have used two codes for response. Here's my code:
Request
var requestFilter = {
urls: [ "<all_urls>" ]
},
extraInfoSpec = ['requestHeaders','blocking'],
handler = function( details ) {
var headers = details.requestHeaders,
blockingResponse = {};
for( var i = 0, l = headers.length; i < l; ++i ) {
if( headers[i].name == 'User-Agent' ) {
headers[i].value = 's';
break;
}
}
blockingResponse.requestHeaders = headers;
return blockingResponse;
};
chrome.webRequest.onBeforeSendHeaders.addListener( handler, requestFilter, extraInfoSpec );
Response
chrome.webRequest.onHeadersReceived.addListener(function(details){
details.responseHeaders[details.responseHeaders.length] = {name: 'Set-Cookie', value: 'some random value'};
return {responseHeaders: details.responseHeaders};
},{urls:["<all_urls>"],types:["xmlhttprequest","sub_frame"]},
["responseHeaders","blocking"]);
Response 2
var responseListener = function(details){
var rule = {
"name": "Set-Cookie",
"value": "Some Random Value"
};
details.responseHeaders.push(rule);
return {responseHeaders: details.responseHeaders};
};
chrome.webRequest.onHeadersReceived.addListener(responseListener,
{urls: [ "*://*/*" ] },
["blocking", "responseHeaders"]);

Resources