Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
Angular - Typescript - How to close window open from app during google oauth2 request

I'm working on google oauth2 request code. I need to click on one button application and open a new window to start google oauth2 flow. I have a redirect uri setted as parameter. I write this function but I have this error into setInterval function:

Blocked a frame with origin from accessing a cross-origin frame

this is the function:

        oauth2SignIn() {
      // Google's OAuth 2.0 endpoint for requesting an access token
      const oauth2Endpoint = 'https://accounts.google.com/o/oauth2/v2/auth';

      // Create element to open OAuth 2.0 endpoint in new window.
      let form = document.createElement('form');
      form.setAttribute('method', 'GET'); // Send as a GET request.
      form.setAttribute('target', 'previewWindow');
      form.setAttribute('id', 'googleFormAuth');
      form.setAttribute('action', oauth2Endpoint);

      // Parameters to pass to OAuth 2.0 endpoint.
      const params = {
        client_id: environment.GAPI_CLIENT_ID,
        redirect_uri: 'https://my-app/services/api/api/google/calendar/callback',
        scope: 'https://www.googleapis.com/auth/calendar.readonly',
        state: 'try_sample_request',
        response_type: 'code',
        access_type: 'offline',
        prompt: 'consent',
      };

      // Add form parameters as hidden input values.
      for (let p in params) {
        let input = document.createElement('input');
        input.setAttribute('type', 'hidden');
        input.setAttribute('name', p);
        input.setAttribute('value', params[p]);
        form.appendChild(input);
      }

      // Add form to page and submit it to open the OAuth 2.0 endpoint.
      document.documentElement.appendChild(form);
      let newWin = window.open('', 'previewWindow', 'popup');
      form.submit();

      setInterval(()=> {
        if(newWin.location.href.includes('my-app') {
         newWin.close();
        }
      })
    }

My focus is to close the newWin when url changed. I have also to read the document because sometimes I have an error printed in the dom, like 401 error by the server. Is it possible to solve this problem?

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!