title: Can I setup geolocation(devtools>sensors) with puppeteer api and node.js
body: <p>I need setup geolocation(lat, lng) in devtools>sensors of chrome with puppeteer api</p>
  
  <p>if I set it with:</p>
  
  <pre><code>    // enable geolocation
      const context = browser.defaultBrowserContext();
      await context.overridePermissions(url, ['geolocation']);
      // set current location to Tokyo Station
      const client = await page.target().createCDPSession();
      await client.send('Emulation.setGeolocationOverride', {
          latitude: 43.0642,
          longitude: 141.347,
          accuracy: 100
      });
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/q4gTj.jpg" rel="nofollow noreferrer">see bottom-right: devtools geolocation</a></p>
  
  <p>this code setup geolocation in page navigation.geolocation(but not in devtools) and work for some sites, for example <a href="https://map.ultra-zone.net/g/" rel="nofollow noreferrer">https://map.ultra-zone.net/g/</a>,
  but if I try "google search", it gave me results not right for the geolocation.
  Another way, if I set geolocation manually in devtools>sensors then result is right</p>
  
  <pre><code>const puppeteer = require('puppeteer');
  
  (async () =&gt; {
      const browser = await puppeteer.launch({
          headless: false,
          slowMo: 250,
          devtools: true
      })
      const page = await browser.newPage();
      const url = 'https://map.ultra-zone.net/g/';
      // enable geolocation
      const context = browser.defaultBrowserContext();
      await context.overridePermissions(url, ['geolocation']);
      // set current location to Tokyo Station
      const client = await page.target().createCDPSession();
      await client.send('Emulation.setGeolocationOverride', {
          latitude: 43.0642,
          longitude: 141.347,
          accuracy: 100
      });
      await page.goto(url);
      await page.screenshot({
          path: 'example.png'
      });
      const result = await page.evaluate(() =&gt; {
          return new Promise(resolve =&gt; {
              navigator.geolocation.getCurrentPosition(position =&gt; {
                  resolve({ lat: position.coords.latitude, lng: position.coords.longitude });
              });
          });
      });
      console.log(result);
  
      await browser.close();
  })();
  </code></pre>
  
  <p>Can anybody describe me how to set geolocation in devtools>sensors with puppeteer api or maybe over 'userDataDir' launchPuppeteerOptions?
  Thanks!</p>