![](https://vk.com/images/apps/mini_apps/vk_mini_apps_logo.svg)
VK Bridge Mock
![Travis](https://travis-ci.org/VKCOM/vk-bridge-mock.svg?branch=master)
This library mocks VK Bridge methods.
Usage
Use in your code instead of using vk-bridge by following way:
import bridge from '@vkontakte/vk-bridge-mock';
bridge.send('VKWebAppInit');
bridge.send('VKWebAppGetUserInfo', {}).then(data => {
});
Or event-based way:
import bridge from '@vkontakte/vk-bridge-mock';
bridge.send('VKWebAppInit');
bridge.subscribe(e => {
if (e.detail.type === 'VKWebAppGetUserInfoResult') {
}
});
bridge.send('VKWebAppGetUserInfo', {});
Please note that some methods may only receive (for example, VKWebAppUpdateConfig
,
VKWebAppViewHide
, VKWebAppViewRestore
, etc.). To obtain data from them you need to use the event-based way and callReceiveOnlyMethod()
import bridge, { callReceiveOnlyMethod } from '@vkontakte/vk-bridge-mock';
bridge.send('VKWebAppInit');
bridge.subscribe(e => {
if (e.detail.type === 'VKWebAppUpdateConfig') {
}
});
callReceiveOnlyMethod('VKWebAppUpdateConfig');
For use without code bundler, include the file dist/browser.min.js
and use as follows
<script src="https://unpkg.com/@vkontakte/vk-bridge-mock/dist/browser.min.js"></script>
<script>
vkBridgeMock.send('VKWebAppInit');
vkBridgeMock.subscribe(e => {
if (e.detail.type === 'VKWebAppUpdateConfig') {
}
});
vkBridgeCallReceiveOnlyMethod('VKWebAppUpdateConfig');
</script>
More documentation regarding VK Bridge is here.
You can also use this library in conjunction with VK Mini Apps API:
import { VKMiniAppAPI } from '@vkontakte/vk-mini-apps-api';
import bridgeMock from '@vkontakte/vk-bridge-mock';
const api = new VKMiniAppAPI(bridgeMock);
api.getUserInfo().then(userInfo => {
});