Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

hosts file

I added an entry to the /etc/hosts file, setting a domain to 127.0.0.1 in order to block a domain. However the edit did not seem to have an effect.

What gives?


os = Tiger

Safari is bombing my console log with:
Unsafe JavaScript attempt to access frame with URL

Mac OS X (10.4.11)

Posted on Feb 17, 2008 10:34 AM

Reply
10 replies

Feb 17, 2008 1:40 PM in response to red_menace

I used vi as root to edit.

I read that you have to change NetInfo's search order, moving the hosts file up in NetInfo's search order in order to have the hosts file block a domain, but they didn't specify which Mac OS version they were referring to, and I thought it better to practice on a test Mac (next week) instead of my MacBook for fear of corrupting the boot cycle. Does that sound necessary, to change the NetInfo search order? Which btw I don't know how to do. I know, rt*m. 🙂

If Firefox is not throwing those errors into the console log, does that mean it's a bug in Safari, or would that mean that Firefox is simply not logging that particular error to the console? Safari is being more verbose in debugging?

Thanks for your knowledge.

Feb 17, 2008 2:30 PM in response to Tim Semic

Not sure how verbose Safari is, you might try looking at the Activity window to see if you get the JavaScript errors in there also.

To change the lookup order (see http://www.macwrite.com/criticalmass/mac-os-x-hosts-regrouped-pf.php - this is an older article, but still works for Tiger):

[1] From the Terminal, check the current configuration
lookupd -configuration

[2] If the 'Host Configuration' does not have DNS following FF and NI, then change the configuration file:
cd /etc
sudo mkdir lookupd (make a new /etc/lookupd/ if it doesn't already exist))
cd lookupd

ls (check for files, just in case the directory already existed)
cp hosts hosts.original (save the original, if needed)

sudo echo LookupOrder Cache NI FF DNS DS > hosts (make a new host configuration lookup order)

[3] Restart for any changes to take effect

Feb 17, 2008 7:18 PM in response to red_menace

Hey,
Thanks for all the help. Red, the instructions you provided allowed me to configure NetInfo Manager to block the domains I was interested in. I used the managed hosts file from accs-net.com as well as adding several domains to it. It proved to be very interesting to load commercial web sites and see the results.

I believe it to be proper to mention here that many sites are solely supported by ad revenue, so when using the knowledge found here you likely would be doing a disservice to web enterprises who are providing you a free service. It is worth thinking about.

Myself I was interested in discovering if blocking domains would eliminate error messages that were getting generated by Safari. I am sad to say that this did not seem to help that problem. The site I am having problems with is myspace.com. Load it and check your console log.

Google "Unsafe JavaScript attempt to access frame with URL" for more info on that issue.

Thank you very much for your help. A very nice tidbit indeed.


Tim

Feb 17, 2008 9:27 PM in response to Tim Semic

I use the hosts file from this site, with the personal webserver configured to show me when something is getting blocked. I realize that some sites depend on ad revenue, but the hosts file usually doesn't block ads that are set in the page source, mostly those that are passed on to some ad server somewhere. If it isn't closely related to what I'm looking at, I am not interested in it anyway.

If the site just has some non-standard (or just crappy) JavaScript, the hosts file probably won't help any. I don't think Safari can block individual JavaScripts, but maybe FIreFox has a plugin along those lines.

Feb 18, 2008 4:09 PM in response to Tim Semic

Here is what I use:

Setting up the webserver, if desired (see http://macmerc.com/sections.php?op=viewarticle&artid=83 ):

[1] Edit the text file at /etc/httpd/httpd.conf (save the original somewhere)
- look for the line "#ErrorDocument 404 /missing.html"
- remove the comment character "#" and save the new file

[2] Add the file missing.html to /Library/Webserver/Documents/
- this can be anything, such as a blank HTML document
- for feedback, use something like <i><strike> ad blocked via hosts </strike></i> or a small graphic

[3] Turn on your personal webserver (System Preferences > Sharing)
- note that this will also allow others to access your /Users/username/Sites folder if your router forwards to it.

Feb 18, 2008 11:10 PM in response to red_menace

Red, I got the 404 working with the strikethrough.

Gnarlodious, I messed with the apple image a bit but then it started doing some funky stuff, like it got very big or stretched out at times depending on the site. I admit I was rushing a bit so I will have to spend some more time on it. When it was working correctly it was pretty cool.

Thanks for sharing that stuff, it's been a pretty fun weekend messing with all that.

hosts file

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.