# Cross origin problem

**URL:** <https://talk.observablehq.com/t/cross-origin-problem/2198>\
**Category:** Help\
**Created:** [July 23, 2019, 7:01pm UTC](https://talk.observablehq.com/t/cross-origin-problem/2198 "2019-07-23T19:01:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yloiko](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/yloiko/32/1964_2.png) [@yloiko](https://talk.observablehq.com/u/yloiko)\
**Post date:** [July 23, 2019, 7:01pm UTC](https://talk.observablehq.com/t/cross-origin-problem/2198/1 "2019-07-23T19:01:17Z")

</div>

Can anybody help me with [https://observablehq.com/@yloiko/vk-api](https://observablehq.com/@yloiko/vk-api)  
By click “VK Login” I want to open popup to login in [vk.com](http://vk.com), but browser close the popup with error(see bellow)

![Untitled](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/5/5d69675d5d9601abe44553c912eb71aa0885056d.jpeg)

---

<div class="post-metadata">

**Author:** ![rezpe](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/rezpe/32/1422_2.png) [@rezpe](https://talk.observablehq.com/u/rezpe)\
**Post date:** [July 24, 2019, 10:56am UTC](https://talk.observablehq.com/t/cross-origin-problem/2198/2 "2019-07-24T10:56:09Z")

</div>

Hi, it seems the server only accepts opening the login from the same site, not another. That’s why you have a crossorigin error.

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [July 24, 2019, 2:35pm UTC](https://talk.observablehq.com/t/cross-origin-problem/2198/3 "2019-07-24T14:35:55Z")

</div>

Something like this appears to work:

```auto
VK = require("https://vk.com/js/api/openapi.js?161").catch(() => window.VK)

```

And then in another cell:

```auto
{
  VK.init({apiId: vk_app_id});
  VK.Auth.login();
}

```

Or perhaps you’d trigger the login call with a button click so that the popup isn’t prevented by the browser.

Related: you shouldn’t need the vkAsyncInit callback in Observable because any cell that references `VK` will automatically await for the library to load. But, you could put it inside the cell if you want.

```auto
VK = {
  window.vkAsyncInit = () => {
    window.VK.init({apiId: vk_app_id});
    window.VK.Auth.login();
  };
  return require("https://vk.com/js/api/openapi.js?161").catch(() => window.VK);
}

```

And lastly, we strongly recommend against selecting from the global document (document.querySelector) in Observable because the behavior is difficult to predict with [Observable’s dataflow runtime](https://observablehq.com/@observablehq/how-observable-runs). See Tom’s guide for more details:

> **[Observable anti-patterns and code smells](https://observablehq.com/@tmcw/observable-anti-patterns-and-code-smells)**
>
> An Observable notebook by Tom MacWright.

---

<div class="post-metadata">

**Author:** ![yloiko](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/yloiko/32/1964_2.png) [@yloiko](https://talk.observablehq.com/u/yloiko)\
**Post date:** [July 27, 2019, 2:58pm UTC](https://talk.observablehq.com/t/cross-origin-problem/2198/4 "2019-07-27T14:58:15Z")

</div>

Yes, but how I can resolve the problem with this servece?

---

<div class="post-metadata">

**Author:** ![yloiko](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/yloiko/32/1964_2.png) [@yloiko](https://talk.observablehq.com/u/yloiko)\
**Post date:** [July 27, 2019, 3:10pm UTC](https://talk.observablehq.com/t/cross-origin-problem/2198/5 "2019-07-27T15:10:12Z")

</div>

Hi, mike! I agree with rezpe, I think he accurately identified the problem, have I any way to resolve the problem.

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [July 27, 2019, 3:35pm UTC](https://talk.observablehq.com/t/cross-origin-problem/2198/6 "2019-07-27T15:35:28Z")

</div>

It looks like you specified “[https://observablehq.com](https://observablehq.com)” as your app domain because that path is currently returned as Access-Control-Allow-Origin header value by [login.vk.com](http://login.vk.com).

For security reasons Observable notebooks run in a different domain context than Observable’s frontend. Your notebooks are running at “[https://yloiko.static.observableusercontent.com](https://yloiko.static.observableusercontent.com)”, and this is the domain you need to specify for your app so that the correct CORS origin value is set by [login.vk.com](http://login.vk.com).
