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 7559063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:32:21+00:00 2026-05-30T12:32:21+00:00

I have a script that I want to be injected into the document BEFORE

  • 0

I have a script that I want to be injected into the document BEFORE load. I.E; it should function as if

<script..>MYSCRIPT HERE</script>

<html>
.
.

I have made a script in chrome that executes correctly (I can alert(0) etc) but, it runs in different environment which is not what I want. I want it to run in the SAME environment as page.

Earlier, I had used a trick where in the startup script I had used

window.location="javascript:<MY SCRIPT HERE>"

which effectively changes the execution environment but for the past few days it isn’t working. I think its a chrome bug fix. Is there any other workaround for this? Note: I can’t add script tags dynamically to the page in the startup script because the document.body etc are unavailable.

I would like to provide you more details of why I need this and my previous solution.
HTML Page which I don’t have control over:

.
.
<script>
function a(){//DOSOMETHING}
</script>
.
.
<script>
a(); <<------ I DONT WANT TO CALL THIS
</script>

Solution: startup JavaScript contains

window.location='javascript:const a=function(){};';<<-CONST used!!

That will force error of re-declaration of ‘a’ when the page actually loads, hence, when a() is called, nothing happens. (clever, right? -_-)

But now, I realized when I do window.location="js:..", even that runs in separate env!

  • 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-30T12:32:23+00:00Added an answer on May 30, 2026 at 12:32 pm

    Chrome probably has a bug in the current build as PAEz pointed out. But yes, a lot of insight on how things can be injected into “document” using chrome extension. Thanks Mike for the post. Will keep that in mind the next time I’m injecting using greesemonkey or something 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that uses BeautifulSoup that I want to make into a
I have a java Script function that i want to call whenever mouse moves
I have the following script that I want to insert into a table, but
I have this script that opens a new page inside a span: $(document).ready( function()
i have script that append sections(div) to my page $(document).ready(function () { var counter
I have the following jquery script that I want to work <?php $script=<<<SCRIPT $(#btn).click(function(){
I have a script that I want to exit early under some condition: if
I have a simple Python script that I want to stop executing if a
I have a Iron Python script that I want to run and then have
I have this script that collects data from users and I want to check

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.