Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8956505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:48:05+00:00 2026-06-15T14:48:05+00:00

I have a small JavaScript file based in JS/jQuery and an additional library. It

  • 0

I have a small JavaScript file based in JS/jQuery and an additional library. It is running perfectly as independent files, but I am having problems getting it up and running in a Chrome extension.

The script checks each image of an HTML page for specific characteristics, and depending on that adds a border around the image.

manifest.json

{
    "name": "ImageId",
    "version": "0.1",
    "manifest_version": 2,
    "browser_action":  {
        "default_icon": "icon.png"
    },
    "content_scripts" : [
        {
            "matches" : [
                "http://*/*",
                "https://*/*"
            ],
            "js" : ["jquery-1.8.3.min.js","jquery.exif.js","content_script.js"],
            "run_at" : "document_start",
            "all_frames" : false
        }
    ],
    "icons":{
        "128":"icon.png"
    }
}

content_script.js:

jQuery(window).load(function(){
    $('img').each(function() {

        var gpslo=0;
        var gpsla=0;
        if (typeof(gpslo) != "undefined" && gpslo != null) {
            var gpslo= $(this).exif("GPSLongitude");
            var gpsla = $(this).exif("GPSLatitude");
        }
        console.log(gpslo+"--"+ gpsla);

        if (gpslo!=0) {
            $(this).css('border', "solid 20px red");  
            $(this).click(function() {
                alert("Long: " + $(this).exif("GPSLongitude") + ", Lat: " + $(this).exif("GPSLatitude"));
            });
        }
        else {

            $(this).css('border', "solid 20px gray"); 
        };

    });
});

Now, when I run this in Chrome on a very simple 1-picture only website, I receive no error at all but just a white page.

Also everything works fine running the script outside of the extension system. I am not quite sure how to explain this better. These are my first steps outside of tutorials, so please be kind 🙂

I uploaded the complete test and extension files to: Working(Html).zip and NotWorking(Chrome).zip.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:48:06+00:00Added an answer on June 15, 2026 at 2:48 pm

    As Sudarshan answered, comment out that document.write code in jquery.exif.js. document.write in a content script erases the previous DOM, and VBscript doesn’t work in Chrome anyway.

    However, that is not the only problem:

    1. When the content script is set to "run_at" : "document_start", as in the question, you must use $(document).ready(). When in doubt, it never hurts to use $(document).ready() anyway.

    2. When the content script is set to "run_at" : "document_idle", as in the files you linked, the script may fire after the document.load event has. So, $(window).load() will not always work.

    3. In Chrome, at least on the test page you provided, it takes up to 6 seconds for the Exif data to come in! (It’s pretty much instantaneous on Firefox.) This means, you need to check the images after a time delay.

    Other, less critical, issues:

    1. Use CSS classes to help with the aforementioned timed checks and to avoid inline CSS.
    2. Use jQuery’s .on(), rather than .click(), so that the handler only is attached once and gracefully compensates for AJAX changes.

    Putting it all together, content_script.js becomes (Update, see below this script):

    $(document).ready ( function () {
        $(window).load (CompForExifPluginInitDelay);
    
        //--- In a content script, the load event may have already fired.
        if (document.readyState == "complete") {
            CompForExifPluginInitDelay ();
        }
    
        $(document.head).append ( '                             \
            <style type="text/css">                             \
                img.myExt_HasExif {                             \
                    border:     20px solid red !important;      \
                }                                               \
                img.myExt_WithoutExif {                         \
                    border:     20px solid gray !important;     \
                }                                               \
            </style>                                            \
        ' );
    
        //-- Use jQuery .on(), not .click().
        $(document.body).on ("click", "img.myExt_HasExif", popupLatLong);
    } );
    
    function CompForExifPluginInitDelay () {
        //-- Exif Init takes somewhere between 1.6 and 6 seconds on Chrome!!!
        var numChecks       = 0;
        var checkInterval   = 444;  //-- 0.4 secs is plenty fast enough
        var maxChecks       = 6 * 1000 / checkInterval + 1;
    
        var imageCheckTimer = setInterval ( function() {
                numChecks++;
    
                findImagesWithLatLong (numChecks);
    
                if (numChecks >= maxChecks) {
                    clearInterval (imageCheckTimer);
    
                    //-- All remaining images don't have lat-long data.
                    $("img").not(".myExt_HasExif").addClass("myExt_WithoutExif");
    
                    console.log ("***** Passes complete! *****");
                }
            },
            checkInterval
        );
    }
    
    function findImagesWithLatLong (passNum) {
        console.log ("***** Pass: ", passNum);
        $("img").not (".myExt_HasExif").each ( function (J) {
            var jThis   = $(this);
            var gpslo   = jThis.exif ("GPSLongitude");
            var gpsla   = jThis.exif ("GPSLatitude");
    
            console.log (J + ": ", gpslo + "--" + gpsla);
            if (gpslo != 0) {
                jThis.addClass ("myExt_HasExif");
            }
        } );
    }
    
    function popupLatLong (zEvent) {
        var jThis   = $(this);
        alert (
            "Longitude: " + jThis.exif ("GPSLongitude")
            + ", Latitude: " + jThis.exif ("GPSLatitude")
        );
    }
    

    which works in all my tests so far, (In conjunction with killing that document.write().




    Update: Using .exifLoad():

    As PAEz pointed out in his answer, the Chrome timing issue seems to be resolved by forcing a manual scan of the images with .exifLoad().

    This works when I tested it, and would be a preferable approach to using a timer.

    So, PAEz’s answer works (in conjunction with Sudarshan’s answer), but my version of the code (addressing the other issues) would be:

    $(document).ready ( function () {
        $(window).load (findImagesWithLatLong);
    
        //--- In a content script, the load event may have already fired.
        if (document.readyState == "complete") {
            findImagesWithLatLong ();
        }
    
        $(document.head).append ( '                             \
            <style type="text/css">                             \
                img.myExt_HasExif {                             \
                    border:     20px solid red !important;      \
                }                                               \
                img.myExt_WithoutExif {                         \
                    border:     20px solid gray !important;     \
                }                                               \
            </style>                                            \
        ' );
    
        //-- Use jQuery .on(), not .click().
        $(document.body).on ("click", "img.myExt_HasExif", popupLatLong);
    } );
    
    function findImagesWithLatLong (passNum) {
        $("img").not (".myExt_HasExif").each ( function (J) {
            $(this).exifLoad ( function () {
                var jThis   = $(this);
                var gpslo   = jThis.exif ("GPSLongitude");
                var gpsla   = jThis.exif ("GPSLatitude");
    
                console.log (J + ": ", gpslo + "--" + gpsla);
                if (gpslo != 0)
                    jThis.addClass ("myExt_HasExif");
                else
                    jThis.addClass ("myExt_WithoutExif");
            }.bind (this) );
        } );
    }
    
    function popupLatLong (zEvent) {
        var jThis   = $(this);
        alert (
            "Longitude: " + jThis.exif ("GPSLongitude")
            + ", Latitude: " + jThis.exif ("GPSLatitude")
        );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small javascript library written by myself. I want to reference it
I have a backbone app with over 50 small JavaScript files. Now I want
I developed a small Javascript/jQuery program to access a collection of pdf files for
I have small bug (I suppose) in my Javascript file. It is simple file
I have small animation using javascript and css. I made one sprite png file,
I have a small script which grabs a file and outputs in Javascript. Then
I have a small web app built in PHP and Javascript/jQuery. The app involves
I have a small javascript function which opens an url in a new tab:
I am making a small calculator (just for JavaScript learning) and I have two
I have been working on a small file manager module in a project where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.