acloudtree

Tag error

Developing a Chrome Extension and the “Origin is not allowed by Access-Control-Allow-Origin Error”

I have been messing around building a Chrome extension and am fetching some resources using good ol’ XMLHttpRequest(). At least I was trying to do so and instead was getting an epic fail.

I am using the google developer debugger to test (tutorial) and saw the following error in the console.

Example:

Origin [YOUR_RESOURCE_NAME] is not allowed by Access-Control-Allow-Origin Error.

I thought I had configured my manifest.json file with the correct permissions.

...snip...
  "permissions" : [
    "https://*.domain.com"
  ],
...snip...

Turns out I was simply missing the trailing slash /.

...snip...
  "permissions" : [
    "https://*.domain.com/"
  ],
...snip...

Hope that helps someone.

Ruby, Rails 3.1, and the dreaded “Could not find a JavaScript runtime” error

While deploying a custom Rails 3.1 application I came across the following error.

Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.

The fix was simple.

Add these gems to your application Gemfile

gem 'execjs'
gem 'therubyracer'

And run bundler.

$ bundle install

(Nerd) Ubuntu 9.10 + installing wireshark

From the command line

1
sudo apt-get install wireshark

Once the process completes, wireshark will be installed. The only problem is that if you open the wireshark application, there will not be any physical eth(N) devices to sniff. So how do we remedy this?

Open the application ‘Main Menu’

PathToMainMenu

Select wireshark properties

SelectWiresharkProperties

We need to change the command from this
Wireshark

To this
GksudoWireshark

And what is the reason? Well the ethernet or wireless devices we are after are owned by root. So if we tack on the gksudo command to the front of the wireshark init command, we are effectively opening wireshark as root. With all the implied responsibilities and permissions, make sense?

(Nerd) Python2.6, Screen scraping, and Javascript cookies

Recently I tried *scraping some data from a website and was running into problems. I don’t have a fix at the moment but I made the first big break through.

My first attempt at scraping the data with Python was met with immediate denial. And I was able to get similar results (though not exact) by disabling cookies in my browser (firefox3.5) and accessing the desired site. The fact that the results were not identical confused me some. But I figured it was a subtle difference in the way Firefox handled the request versus how I was handling the request programmatically with Python, mechanize, urllib2, and cookielib.

Still, after several hours I still was unable to make the desired request to the server. So I started doing some digging. It turns out that these libraries are unable to automatically handle cookies set by Javascript. So, to test this, I disabled Javascript in my browser, made the request, and got the exact same results. YES!!!

As a quick test I was able to extract the cookies’ value using the LiveHeader extension in Firefox. I then took this value and manually assigned it to the header of my Python request. I then got the desired results in my Python program. I’ll post an example of my solution when I get it up and running.

Troubleshooting:

In your browser I would do the following in order to try and recreate what is happening in your program.

  1. Disable Javascript
  2. Disable Cookies
  3. Access headers with Firefox plugin

*Programmatically extracting data from a website

Copyright © Jared Folkins
Programming, Computers, Writing, Economics, and Life

Powered by WordPress