Skip to content

Network error with offline in Chrome Extension #416

@mattbarry

Description

@mattbarry

I'm working on a web browser extension in which I would like to use AppSync to query data from DynamoDB. To get up and running quickly, I generated the "Event App" sample project in the AppSync API console. Then I added the following code to my extension's background page:

import appSyncConfig from './aws-exports';
import AWSAppSyncClient from 'aws-appsync';
import gql from 'graphql-tag';

const client = new AWSAppSyncClient({
  url: appSyncConfig.aws_appsync_graphqlEndpoint,
  region: appSyncConfig.aws_appsync_region,
  auth: {
    type: appSyncConfig.aws_appsync_authenticationType,
    apiKey: appSyncConfig.aws_appsync_apiKey
  }
});
  
const query = gql`
query {
  listEvents(limit: 1000) {
    items {
      id
      name
      where
      when
      description
      comments {
        items {
          commentId
        }
      }
    }
  }
}`;

client.query({
  query
})
.then(result => console.log(result));

This code works as expected when I run it as a temporary extension in FireFox. I can see the result of my query in the console and I can see some reduxPersist entries added to local storage. It also works when I run it in the context of a web page (using a file:// URL) under both FireFox and Chrome.

However it bombs when I run it as a Chrome extension with the following Network error:
Screen Shot 2019-05-26 at 2 37 06 PM
Setting disableOffline:true fixes the query. However I lose offline support and nothing gets written to local storage.

I realize that browser extensions are probably an edge case for the JS SDK, but I'm wondering if anybody could offer some guidance in terms of debugging this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    offlineOffline related issues that we run intoto-be-reproducedWe need to reproduce this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions