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

  • Home
  • SEARCH
  • 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 7546179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:07:58+00:00 2026-05-30T09:07:58+00:00

Here is a simple page: <!DOCTYPE HTML> <html lang=en> <head> <meta charset=UTF-8> <title>Test page</title>

  • 0

Here is a simple page:

<!DOCTYPE HTML>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test page</title>
    <script type="text/javascript">
        function foo (num) {
            alert(num);
        }
    </script>
</head>
<body>
    Hello World
    <script type="text/javascript">
        foo(2);
    </script>
</body>
</html>  

I’d like to write a Chrome extension to prevent the execute of the bottom script(foo(2)).
I tried to write a content script which removes the last script tag with:

document.body.removeChild(document.body.lastChild);  

but it does not work.

I think this may be because the content script runs after the last script line has executed. then I tried to set the run_at to document_start or document_end, but none of them work for me..

  • 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-05-30T09:08:00+00:00Added an answer on May 30, 2026 at 9:08 am

    I faced the same problem during development of the Don’t track me Google User script / extension.

    #Important note
    The window object in a Chrome contentscript cannot be accessed directly, in any way.
    I have tested many methods, and the only reliable method is injecting the code through a dynamically created script tag. Have a look at this answer, or my extension’s source code for more information.

    I solved it by using Object.defineProperty. With this method, you can define a property, and specify information about the getter, setter and property descriptors. In your case:

    Object.defineProperty(window, 'foo', {
        value: function(){/*This function cannot be overridden*/}
    });
    

    Or, if you want to capture the variable, and use it later:

    (function() {
        var originalFoo = function(){/*Default*/};
        Object.defineProperty(window, 'foo', {
            get: function(){
                if (confirm('function logic')) return function(){/*dummy*/};
                else return originalFoo;
            },
            set: function(fn){originalFoo = fn;}
        });
    })();
    

    ##Bug in Chrome 17 [Bug #115452](http://code.google.com/p/chromium/issues/detail?id=115452) [Fixed!](http://code.google.com/p/chromium/issues/detail?id=115452#hc4)
    In Chrome 17, using V8 3.7.12.12 (but not in Chrome 16, using V8 3.6.6.19), **Function declarations override the property descriptors**.
    See http://jsfiddle.net/bHUag/
    Note that this bug *seems* to not be applied when the function declaration and property descriptor method are in the same block. This is false, though. The effect is not visible, because function declarations are always evaluated before the code block. So, `function foo(){}` is evaluated first, then the rest of the code.

    <script>
    Object.defineProperty(window, 'foo', {value: function(){return 5;} });
    </script><script>
    function foo(){return 1};
    alert(foo()); // Shows 5 in all browsers except for Chrome v17
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code: <%@ page language=java pageEncoding=UTF-8 contentType=text/html; charset=utf-8%> <% // some code
I have a simple PhoneGap application as fallows: <!DOCTYPE HTML> <html> <head> <title>PhoneGap powered
I have simple html page with 3 tabs: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0
I'm having trouble with the layout of a simple HTML page. Please help. Here's
I have this simple code in facelets numbers.xhtml: <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html
Here's a simple web page. I would like the text as well as the
Here i am sending you my code for simple navigation page...! I am not
I have a simple JSF 2.0 composite component example. <!DOCTYPE html PUBLIC -//W3C//DTD XHTML
Here's my problem: I have a form in index.html, it will have a text
I have the following snippet: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0

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.