A method for accessing a text file from a pastebin using CORS

My goal is to utilize CORS for fetching code snippets from a pastebin and then executing them in a web browser.

Here is some work-in-progress code: http://www.example.com/code-snippets.html

The code is syntax highlighted with options to run it, etc.

I aim to offer a straightforward service where users save text in a public location and then query:

http://www.example.com/code-snippets.html?queryURL=specific-url

For instance, the URL could be:

http://www.example.com/code-snippets.html?queryURL=http%3A%2F%2Fpastebindemo.com%2Fraw.php%3Fi%3Dd3m02ln8

However, when using CORS, the repository returns an empty file. Is CORS possibly blocked by certain systems (e.g., pastebindemo.com)? Or am I making an error somewhere?

I have attached images from the Firefox debugger that show what seems like a blank response from CORS, along with the GET headers which may provide insight.

Below is my CORS code snippet:

function CORSRequest(url) {
   var xhr = new XMLHttpRequest();

   if ("withCredentials" in xhr) {
      // Check if the XMLHttpRequest object has a "withCredentials" property.
      // "withCredentials" only exists on XMLHTTPRequest2 objects.
      xhr.open("GET", url, true);
   } else if (typeof XDomainRequest != "undefined") {
      // Otherwise, check if XDomainRequest.
      // XDomainRequest only exists in IE, and is IE's way of making CORS requests.
      xhr = new XDomainRequest();
      xhr.open("GET", url);
   } else {
      // Otherwise, CORS is not supported by the browser.
      throw new Error('CORS not supported');
   }

   if (xhr) {
      xhr.onload = function() {
         // process the response.
         document.getElementById("sparql").value = xhr.responseText;
      };
      xhr.onerror = function() {
         alert('Not loading.');
      };
   }
   xhr.send();
}

Answer №1

If you want to enable it on the client side, one option is to utilize a CORS proxy such as cors.io, or you have the choice of developing your own solution.

When using cors.io, you can modify the service's URL by adding the proxy in front like so:

https://cors.io/?http://pastebin.com/raw.php?i=grUU9zwE

Answer №2

It appears that as of February 17, 2022, this method is effective: . This website serves as a proxy to help with CORS issues. It is important to conduct your own research and exercise caution when utilizing this link. Please note that I am not affiliated with the aforementioned website.

Answer №3

When you purchase a Pastebin Pro subscription, your pastes are automatically accessible to the public via CORS (utilize the raw link)

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

Hide Navbar when clicking on menu item

I'm struggling with finding a solution to this issue, as I am unsure of how to proceed. The problem I am facing is that when I click on an item, the router-view changes correctly, but the menu remains open. I would like it to close after a click. ...

Attempting to create a fresh string by substituting certain characters with different ones

Exploring TypeScript, I encountered a puzzle where I needed to substitute specific characters in a string with other characters. Essentially, replacing A with T, T with A, C with G, and G with C. The initial code snippet provided to me looked like this: e ...

What is the process for refreshing the component content in Angular 2?

There was a moment during execution when my URL had the following appearance: http://localhost:4200/personal/51c50594-a95c-4a18-ac7b-b0521d67af96 I desire to visit a page with a different GUID and different content. http://localhost:4200/personal/{other ...

What is the process for running "node server.js" within codelab?

I am currently going through a codelab tutorial on Bitbucket at this link After installing node.js for the first time, I encountered an error when trying to run the server.js file: node server.js The error message "node: Command not found" appeared even ...

communicating between domains - js

Background: My latest project involves creating a web application that can download and display housing prices. The data source can be found at The Initial Plan: I aimed to fetch the data directly from the provided link using javascript, and then conver ...

Steps for clearing the UIWebView application cache for HTML5 applications

I recently encountered a problem where the HTML5 application cache stopped working in a native container using UIWebView to display HTML content. The cache.manifest file was updated, and UIWebView started downloading the process but failed at a specific ...

What is the best way to deactivate a button using AngularJS?

$scope.date = moment(currentDate); $scope.date1 = moment(currentDate).add(-1, 'days'); function checkDate(){ if ($scope.date > $scope.date1) { return true; } else{ return false; } }; checkDate(); ...

Developing modular applications with Vue.js and leveraging locally installed NPM packages

I am currently working on developing a modular application using Vue through the vue-cli-service. The main application and its modules are located in separate folders, with a structure that looks something like this: -- app/package.json /src/** -- mo ...

Tips for invoking C language code from JavaScript by using the js-ctypes extension in Firefox

I need assistance with developing a Firefox extension that requires calling native C code. Here is my C program code: #include<windows.h> int add(int a, int b) { return(a + b); } And here is my JavaScript code: var {Cu} = require('chrome ...

Include an HTML attribute within a given string

Using jQuery, I am adding HTML content to a div. The variables rowString and inputString have been defined beforehand: $("#filterContainer").append( rowString + `<label class='filterLabel' for=${filter}>${filter}< ...

Tips for preserving input field data in an AngularJS scope variable

I am having trouble storing textbox values in my 'Values' variable. When I enter values in the textboxes, it seems to be getting the hard-coded values instead. Can someone please help me with this AngularJS issue as I am new to it? Here is the co ...

After zooming in on the canvas and panning, I encountered a problem where I was unable to drag objects within the canvas. Instead, the canvas continued to pan as I tried to move the objects

1) I have the ability to pan the canvas and drag images without scaling or zooming. 2) When scaling or zooming, I can still drag images within the canvas. 3) However, if I try to pan the canvas after zooming and then attempt to drag images, only the canv ...

Is it possible to alter the hyperlink (href) dynamically according to the H2 content?

I am currently assisting a major affiliate website in dynamically replacing their links. They have expressed a desire to utilize the content of the H2 tags that follow their images with the class name wp-block-image. This is an example of the code: < ...

What is the best way to develop a PHP proxy script to manage CORS problems when making API requests?

I am facing an issue where I need to call an API, but due to CORS problems, I have to create a PHP proxy file. However, the PHP code I wrote does not seem to be working as expected, leaving me stuck. Below is the script I'm using to make the API call ...

Nightwatch.js feature not functioning properly in a 'closing' manner

I'm facing an issue where I need to execute a function at the beginning of my test before proceeding with the rest of the test steps. Here is the custom command I am using, named internalAdviceLinksHtml: const solr = require('solr-client') ...

I'm confused about what I did wrong with Node.js. The server.js is up and running, but I'm unable to view the

I have made some progress so far and I am currently running this code on Putty. var http = require('http'); var fs = require('fs'); const PORT = 8080; http.createServer(function(request, response) { var url = request.url; switc ...

What could be causing the issue with setting the right margin (element.style.marginRight = xxx) not working?

I used JavaScript to set the margin-right of a div when the window is resized. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device- ...

What is the best method for implementing click functionality to elements that share a common class using only pure JavaScript

I am struggling to figure out how to select specific elements with the same classes using only pure JavaScript (no jQuery). For example: <div class="item"> <div class="divInside"></div> </div> <div class= ...

Error: Unable to locate the tslint command

After attempting to utilize tslint --fix, I encountered the error message bash: tslint: command not found.... To install tslint, I ran the following command: yarn global add tslint typescript. The operating system on my machine is Centos 7. ...

What is causing ES6 Class properties to be concealed by Higher Order Functions?

UPDATE: Added new screenshots to provide clarity at the end. My current challenge involves utilizing high order functions to combine subclasses/mixins. I've noticed that I can only access properties from the first class I extend, and only properties ...