Adjusting the XHR 'Referer' header within a Chrome application

Is there a way to adjust the 'Referer' header in my Chrome app? When I try to set it using the following code:

xhr.setRequestHeader('Referer', 'http://example.com/');

I receive an error message that says:

ajax.js:15 Refused to set unsafe header "Referer"

I came across an older discussion where someone manipulated the 'Referer' field using chrome.webRequest, but this extension is no longer accessible in Chrome apps. Chrome.webRequest functionality has been deprecated! Despite many suggestions on Stack Overflow advising its use, it is no longer supported by Chrome. How can I update this header?

Answer №1

web-server-chrome provides a useful tool called ChromeSocketXMLHttpRequest. This object can be integrated into your project by cloning the repository and running minimize.sh to generate a single minimized file for easy inclusion. By utilizing ChromeSocketXMLHttpRequest, you can effectively substitute it for the standard XHR in your project.

Answer №2

Even though Chrome Apps cannot directly access the API, using the <webview> element provides a workaround with its request interface that can modify requests through the use of the webRequest feature.

This method involves creating a "proxy" page that handles XHR's on your behalf, embedding it within a webview, and then adjusting its requests as needed. While this adds an extra step, it does offer a solution to achieve the desired functionality.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm curious as to why styled components weren't working before

I'm attempting to utilize the before on styled components in React, but it doesn't seem to be functioning correctly. Prior to adding before, the background image was displayed, but after its inclusion, the image is no longer showing up; import st ...

What is the best way to create a TypeScript interface or type definition for my constant variable?

I'm facing challenges in defining an interface or type for my dataset, and encountering some errors. Here is the incorrect interfaces and code that I'm using: interface IVehicle { [key: number]: { model: string, year: number }; } interface IV ...

Update the HTML page when switching between tabs

Currently, I am experiencing an issue with tab navigation in HTML. Within my code, I have two tabs named #tab1 and #tab2, each containing a form. The problem arises when I input data into #tab1, switch to #tab2, and then return to #tab1 - the information I ...

"Looking to replace a character class pattern using regex in JavaScript? Here's how you can easily

I have a string: "\W\W\R\" My goal is to transform this string using regular expressions into: <span>W</span><span>W</span>\R This is the code I'm currently using: "\W\W\R".replace(/&b ...

Sketch on canvas using vue framework

I am trying to modify a selection tool using rectangles that was created with JS and HTML in Vue.js. Here is the original version: https://codepen.io/sebastiancz/pen/mdJVJRw initDraw(document.getElementById('canvas')); function initDraw(canvas) ...

Analyzing an Object through Functions

var Car = function(name, year) { this.name = name; this.year = year; this.print = function() { console.log(name+" "+year); } } var tesla = new Car("tesla", 2018); tesla.print(); tesla = JSON.parse(JSON.stringify(tesla)); console.l ...

What is the proper way to create a regex pattern that specifies 'without any spaces'?

I need assistance in creating a regex expression that specifies "and NO whitespaces". I have to incorporate this into the following if statement shown below: $('#postcode').blur(function(){ var postcode = $(this), val = postcode.val(); ...

Exploring JSON parsing in AngularJS without running into reserved keywords

var jsonURL='../../json/xx.json' var myApp = angular.module('myApp',[]); myApp.controller('loaddata_traceroute', ['$scope','$http',function($scope, $http){ $http.get(jsonURL).success(function(data) { ...

Unable to utilize ng-Bootstrap datepicker

I recently cloned the quickstart project from the tour of heroes guide on Angular's official website, and I wanted to incorporate the ng-Bootstrap datepicker. However, I encountered some issues with its functionality. Below are the key components of m ...

What is the best way to add 1 to the number in my array?

I'm currently learning JavaScript and I have a function that should increment my count by 1 every time it's called. However, when I run it in the console, it just keeps repeating 1. Does anyone have any suggestions? var output = []; var count = ...

Experiencing difficulty importing Materialize CSS JS into React

Good day everyone, I've been facing challenges in implementing materialize css into my react-app, specifically with the JavaScript files. After trying various methods, I believe that I have made some progress using the following approach: In my &ap ...

Tips for sending multiple commands in ngrx/effect (redux-observable)?

In my Angular 6 project, I am using ngrx/store to manage state. I have an effect that handles updating data and based on certain conditions, I need to dispatch different actions. What will be the impact of using switchMap instead of map in this scenario? ...

Issues with jQuery AJAX, occasionally experiencing repeated requests

Currently, I am in the final stages of revamping our JavaScript system by transitioning from Prototype to jQuery. We have numerous AJAX requests that are triggered when specific events occur on certain elements. One instance of this is when a new event is ...

Why Electron is refusing to open a JSON file

Currently, I am attempting to populate filenames using JSON for the onclick='shell.openItem('filename') function. While the console.log(data[i].url) correctly displays the kmz files for each button, I encounter an error when clicking a butto ...

JavaScript allows for the hiding of the Android navigation bar on web apps in Chrome, which includes the virtual back, home screen, and other buttons

In the process of developing a web application, I am aiming to provide users with a fully immersive fullscreen experience. This entails hiding not only the Chrome address bar at the top but also the navigation bar at the bottom (which includes virtual back ...

React-dnd supporting multiple draggable and droppable elements

I am facing a challenge with making multiple elements draggable using react-dnd. I have an array of 4 fields that I would like to make draggable, but when I map through the array and give each element a className of 'element', they do not move as ...

Master the art of navigating the Windows Sound Recorder with the power of JavaScript

I am creating a project that involves controlling the Windows sound recorder for tasks such as starting, stopping, and saving recordings. Is there a way to do this without displaying the recorder window? I would appreciate any assistance in solving this. ...

The data retrieved from the API call is outdated

I am struggling with a weather web API that is only showing old data when called in the code. However, when I enter the API URL directly into the browser, it displays the most up-to-date information for the current city. Can anyone help me troubleshoot why ...

There are various iterations of html2canvas available

After upgrading html2canvas from v0.5.0 to v1.0.0, a specific function ceased to work on iOS. Therefore, I am interested in utilizing v0.5.0 on iOS and v1.0.0 on other devices. Is there a way to incorporate and switch between both versions of html2canvas ...

In Internet Explorer 11, React 15.4.1 does not support using objects as valid child components

When trying to render a collection of children in React, make sure to use an array instead of objects. If you encounter the error "Objects are not valid as a React child," consider wrapping the object using createFragment(object) from the React add-ons. Do ...