Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change how we check if app is embedded #1458

Merged
merged 4 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased
----------

* Internal update, adding App Bridge 3 for redirect (only). [#1458](https://github.com/Shopify/shopify_app/pull/1458)

19.1.0 (June 20, 2022)
----------

Expand Down
10 changes: 0 additions & 10 deletions app/assets/javascripts/shopify_app/app_bridge_2.0.12.js

This file was deleted.

10 changes: 10 additions & 0 deletions app/assets/javascripts/shopify_app/app_bridge_3.1.1.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//= require ./app_bridge_2.0.12.js
//= require ./app_bridge_3.1.1.js

(function(window) {
function appBridgeRedirect(url) {
Expand Down

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions app/assets/javascripts/shopify_app/redirect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//= require ./app_bridge_redirect.js
//= require ./app_bridge_utils_3.1.1.js

(function () {
function redirect() {
Expand All @@ -10,15 +11,12 @@

var targetInfo = JSON.parse(redirectTargetElement.dataset.target);

if (window.top == window.self) {
// If the current window is the 'parent', change the URL by setting location.href
window.top.location.href = targetInfo.url;
} else {
// If the current window is the 'child' or embedded, change the parent's URL with
// App Bridge redirect. This case can happen when an app updates its access scopes,
// or the unlikely scenario where the shop thinks the app is installed, but the
// app does not have an record for the shop.
var appBridgeUtils = window['app-bridge-utils'];

if (appBridgeUtils.isShopifyEmbedded()) {
window.appBridgeRedirect(targetInfo.url);
} else {
window.top.location.href = targetInfo.url;
}
}

Expand Down